please help me i can’t think of a way to optimise my code for numbers in range 10^15
Can't handle bigger numbers
to avoid overflow, before multipying you can check
if(mul>n/k)
return 0;
because if above statement is false,then mul*k doesnot overflows for long long
i am already checking that:
see your mistakes!
what is the logic behind n/num??
think of a case when n=10^17, num=10^7 and mul=10^14, so now if you do it the old way then mul<=n so num gets multiplied to it again and mul becomes 10^21(which results in overflow), so the logic behind is to avoid possible overflow after multiplication!!
If your doubt is clear mark it as resolved.