Can anyone help me with Number of Factors problem?

I got ac in all the testcases except the last one in which i am getting a RE (SIGFPE). I cannot figure out why am i getting this error. I don’t think there is any division by zero or invalid access of memory or overflow of memory. Please help.

Problem link:

My solution:

hey @abhinav_7538 you just need change the max_num in your code…changing it to 1010 your solution got accepted… here is my submission of your code with modification



Adding to above answer, you should know what causes SIGFPE.

Usually, the 3 most common things causing SIGFPE is-

  1. Division of a number by 0
  2. Modulo (%) of a number by 0
  3. Overflow in a function which resulted in the function returning 0 (which was further used for division or modulo)

But i don’t see why my solution was wrong…

Even i tried debugging your code. I feel the SIGFPE error was due to this condition-

for(;primes[j]*primes[j] < temp+1;j++)

It might be possible that j exceeds the range of index, and a default value of 0 gets assigned to it. (And since primes are being calculated to 1000, raising the upper limit must have added 1-2 extra primes such that it didnt go out of index then)

your solution was not wrong…but it’s always better to have limits bit higher than required…

1 Like

Thanks guys. I think what vijju123 suggested is probably the reason.