0

Why some books state that Primes is a NP problem if, as a decidibility problem, it can be solved in polynomial time?

A simple example:

A number can has its primality tested by dividing it by all numbers from 2 to \sqrt(n). It then takes at most \sqrt(n) operations to find if its prime.

After talking to colleagues, some stated that \sqrt() method is (was) in NP, but after reading about it it seems to take constant time for a certain precision (precision does not matter for this kind of problem).

Why then?

P.S.: Just to state, I know that P is within NP. The thing is not about it being contained, but it beign in NP and not in P (no polynomial solution).

Tiago Duque
  • 141
  • 5
  • As a prorgramming note, You do not need to calculate sqrt(n) for this algorithm. You merely iterate until you find that n*n is greater than your number. Thus the complexity of the sqrt implementation does not need to be factored into your algorithm. – Cort Ammon May 19 '17 at 19:12
  • Can you state precisely what the book states "Primes" is? There's probably hundreds of problems related to primality, some of which are P and others are not. Also, it matters greatly what they define 'n' to be. If n is the number of bits in the number being tested, the result will be different than if n is the value of the number being tested. – Cort Ammon May 19 '17 at 19:14
  • By the way, from the sqrt(n) method we can only prove that Primes is in coNP. Proving Primes in NP is harder. – chi May 19 '17 at 19:15
  • Well, it was an outdated question. It was not well defined and, after asking my professor about it, he said that it was the problem of finding the n'th prime. Before AKS, I think this was a NP problem, but with this polynomial algorithm the complexity got lower. – Tiago Duque May 20 '17 at 19:50