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)).
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.
Factoring: It is not known to be NP-complete.
Integer Factorization is in P – Optimization Online.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With