spoj gives me time limit exceed for even a simple problem !!!

I am new at SPOJ comminity

I am trying to solve a simple problem at :

my code is available at :

what is wrong with SPOJ ? it gives me “Time limit exceed”

Your code complexity is O(n) per test case. But the maximum value of n can be 2^63-1. Hence it will not pass on online judge. In one sec, approx 10^9 operations can be executed on cube cluster. Since the time limit of the problem is 21 sec, so you will have to write a solution that has 21 * 10^9 operations to be executed.

You can use Miller-Rabin primality test to check whether a number is prime or not.

Happy coding and welcome to SPOJ !!!

1 Like

I wish the problem was as simple as it looks.