I am using the following code to calculate the number of Divisor of a large number(10^16 order). Code Link:- https://ideone.com/eBnZ37 (The output for 11 should be 2 whereas it’s giving me 4).
@horcrux2301 this question seems to be related to April Circuits 2017 on hackerearth.
Doesn’t it?
The contest will be completed within few hours then you can check the editorial.
if(Miller(n))
{
ans = ans*2; // ans2 to ans*2
}
else if(sq*sq == n && Miller(sq)) // sqsq to sq*sq
{
ans = 3;
}
else if(n != 1)
{
ans *= 4;
}
Minutely observe the segment-
else if(n != 1)
{
ans *= 4;
}
In case of prime number 11 (as you took), our loop exits at prime 3 (if i understand the working correctly) and before it, no prime is able to divide n=11 (in your case). The value of ans was 1 after the loop and after the if-else it becomes 4. I think the problem is that either prime numbers were not considered while writing the program,
or it might be the “Miller” function (Since it is making ans x 2 and would give correct answer of 2 if executed) .
Yup, thats what i said. But theres 1 more thing to consider. Above it is
` if(Miller(n))
{
ans = ans2; // ans2 to ans2
}
I feel it might be possible that a big in miller is causing prime numbers to go to below if (while intention was they get executed in this if only). What are your views?