Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is factoring in NP, but not in P?

Factoring: Gven an integer N, find integers 1 < a, b < N such that N = ab if they exist, otherwise say N is prime.

I know that primality testing is in P, but why not factoring?

Here is my algorithm:

For each a = 1 ... sqrt(N)
    if(N % a == 0)
        b = N/a
        add (a,b) to the result
    Endif
EndFor

This runs in O(sqrt(N)).

like image 227
Nayana Avatar asked Nov 19 '13 14:11

Nayana


People also ask

Why is factoring in NP?

It is in NP, because a factor p<k such that p∣n serves as a witness of a yes instance. It is in co-NP because a prime factorization of n with no factors <k serves as a witness of a no instance. Prime factorizations are unique, and can be verified in polynomial time because testing for primality is in P.

Is factoring a number NP-complete?

Factoring: It is not known to be NP-complete.

Is integer factorization in P?

Integer Factorization is in P – Optimization Online.

Is factoring primes NP-hard?

No. Integer factorization is not NP-hard (so not NP-complete). (This isn't proven, but it's generally thought to be the case.) So, while doing a polynomial-time integer factorization would be hugely significant (and make all asymmetric encryption in the world useless), it would not prove P=NP.


1 Answers

The input size of a single numeric value, is measured by the length of its binary representation. To be precise, the size of an input numeric value n is proportional to log_2(n). Therefore your algorithm runs in expotential time.

For instance, suppose we are factoring a number N with your algorithm. If N is prime, you have to test at least sqrt(N) factors. (Or alternatively you can compute a prime number table for this but it is still not linear).

Anyway, you test for sqrt(N) times. But the size of the problem is defined as S=log2(N). So we have N=2^S. Therefore it's a sqrt(2^S)=2^(S/2) which is expotential.

like image 200
phoeagon Avatar answered Sep 20 '22 12:09

phoeagon