I'm learning about P
and NP
.
I've read that the problem of deciding if a given number is prime is a problem in P, which means that it has a polynomial-time algorithm which solves it.
I've also read that this fact was proven in 2002, with the algorithm of AKS.
As we all know, we can decide if a particular number is prime by running till its square root.
pseudo-code:
isPrime(N):
sqrt(N) <- squareRoot(N)
for i from 2 to Sqrt(N)
if (n mod i == 0)
return false
return true
My question is simple:
Why the algorithm above doesn't prove that this problem is in P?
Thanks :)