I have to find the maximum number which is less than or equal to SQUARE_ROOT(N) and divides N.
Most direct solution is of O(SQUARE_ROOT(N)) , is there any O(logN) solution since number can be vary large in the range of 10^18.
If N equals to p*q, where p and q are prime numbers, you should find this primes first to answer your question. So this problem in general is not easier than Integer factorization. And there is no known algorithm with O(logN) complexity.
No algorithm has been published that can factor all integers in polynomial time, i.e., that can factor b-bit numbers in time O(b^k) for some constant k. Neither the existence nor non-existence of such algorithms has been proved, but it is generally suspected that they do not exist and hence that the problem is not in class P. The problem is clearly in class NP but has not been proved to be or not be NP-complete. It is generally suspected not to be NP-complete.
May be you could find something useful among different factorization algorithms.
If N is composite, then
N = MaximumDivisor(N) * MinimumDivisor(N).
Related
Bear in mind I'm almost a complete noob at complexity theory.
I was reading about how AKS Primality shows that numbers of size n can be shown to be prime or composite in polynomial time. Given that, does that imply finding all prime numbers less than a number n is also doable in polynomial time and thus the algorithm runs in FP. Additionally, does this imply that counting all primes less than n is not in #P?
well. What aks says it that primality testing for a number n is O(b^k) where b = log2(n) and k is some integer.
So, if your questions is is listing all the primes from 1 to n also O(b^k). Then the answer is trivially no because the number of primes less than n is O(n/logn). Therefore you would need O(n/log(n) ) just to list them
If your question is does there exist a k such that the complexity of listing all the primes less than n is in O(n^k).
Then the answer is trivially yes because the most trivial form of sieve is O(n^(1.5)).
If anything is unclear please let me know
I'm wondering about the NP-completeness of a variation of the Subset-sub problem:
Subset-sum problem:
Given a set of integers and an integer s, does any non-empty subset sum to s?
This problem is known to be in NP and be NP-complete. Now consider the variation:
Subset-sum problem (congruence variation):
Given two integers s and m and a set of integers modulo m, does any non-empty subset sum to s mod m?
(i.e., all the numbers in the set are modulo m and the expected sum s is also in mod m).
I'm wondering if this problem has been studied before? (Would like to know if it is NP-complete or not). Does anyone know if there is any paper or similar variation of the Subset-sum problem? Thank you!
Yes, this problem is also NP-complete. Since normal subset sum is NP complete, there is a reduction of some other NP-complete problem to subset sum.
The same reduction will also work to prove that modular subset sum is NP complete, if you can additionally generate a sufficiently large modulus with a size that is polynomial in the input size. The modulus just has to be bigger than the largest number used in the subset sum solution, and then the difference between subset sum and modular subset sum is irrelevant.
For any reduction I can think of, it is easy to generate such a modulus. Remember that it is only the size of the modulus that has to be polynomial in the input size, so, say 100^(N^2) works fine -- it's only 2*(N^2) digits long.
Subset sum problem: Given a set of numbers S and a target number let say 0. The aim is to find a subset S’ of S such that the elements in it add up to 0. I heard that this problem becomes polynomial if the size of S’ is given.
For example, if you have a clue that 3 elements add up to 0 we can come up with complexity O(n^3).
The class P consists of those problems that are solvable in polynomial time. For example, they could be solved in O(n^k) for some constant k, where n is the size of the input.
(n^k) denotes the number of subsets of size k of [n]; or, equivalently, the number of ways in which we can select k diferent elements from an n-element set.
With n elements; a k-subset of a set is a subset with k elements.
Therefore let say there is an algorithm in polynomial time that finds or locate the k-subset that sum to 0 from n elements. I mean if k is an input of the algorithm such that k can also be greater than 3. Can we say k is constant or what?
If the running time of an algorithm for some problem with some input is bounded by O(n^k), it depends on various things whether this runtime bound is considered to be polynomial, pseudo-polynomial or none of these. If k is some specific constant like k=3, the bound is polynomial. If k is part of the input, the runtime bound is not considered polynomially bounded.
The concept of runtime bounds is briefly explained here; however note that informal usage of the term 'polynomial runtime bound' is usually somewhat sloppy. In the most exact sense, an algorithm A solving a problem P can have a runtime bound that is polynomially bounded in the encoding length of its input. This means that the the bound also is to be seen in relation to the specific encoding of instances of P for A.
Furthermore, as usually a binary encoding of numbers is used for algorithms, the encoded numbers may grow exponentially in their encoding length. If A has a runtime bound that is polynomially bounded in a numeric value of its input, but not bounded in the encoding length of the input, the bound is said to be pseudo-polynomial, as briefly explained here.
I hope this helps, the specific details are usually a bit inaccurate in informal explanations.
How does these problems fall into the tapestry of the P, NP, NP-Hard, etc... sets? I don't know if any such problems even exists, but what initiated my thought process was thinking of a decidable of the travelling salesman problem:
Given a list of cities and the distances between each pair of cities, and a
Hamiltonian path P, is P the shortest Hamiltonian path?
I suspect that we cannot verify the "shortestness" of P in polynomial time, in which this decision problem is not even in NP. So where does it fall in this case?
This problem is in co-NP. You can think of NP as the class of problems where if the answer is yes, there is a small amount of information I could give you that would convince you of this. For example, the problem
Is there a Hamiltonian cycle in G with cost at most k?
is in NP, because if the answer is yes, I could just give you the cycle and you could check it to see whether it's valid. Coming up with that cycle is hard, but once you have the Hamiltonian cycle it's really easy to use it to check the answer.
The class co-NP consists of problems where if the answer is no, there's a small amount of information I could give you that would convince you of this. In your case, suppose that no, P is not the shortest Hamiltonian path. That means that there's some shorter path P'. If I gave you P', you could easily check that P wasn't ideal. Coming up with P' might be really hard (in fact, it's co-NP-hard!), but once you have it it's pretty straightforward to use it to confirm the answer is no.
Hope this helps!
Given two integers n and m, are there exactly m prime numbers p <= n?
This can be solved in about O (n^(2/3)) and possibly slightly faster, but the problem size is of course not n but log (n), so it takes sub-linear time in n, but exponential time in the problem size. That's not worse than you'd expect from a problem in NP. However, I cannot see any possible information that would allow you to check this quicker.
(Actually, there is an algorithm which determines the number of primes <= n in about O (n^(2/3)) steps, but there is no known algorithm that can check an answer faster than finding the answer. )
Given integers n and k, is 2^n - 1 the k-th Mersenne prime?
It is possible to prove that p is prime in time polynomial in the size of p if a complete factorisation of p + 1 is known, and if p = 2^n - 1 then the complete factorisation of p + 1 is trivial.
However, that is polynomial in the size of p. 2^n - 1 can be checked for primality in time that is polynomial in n. However, that is not polynomial in the size of the problem, which would be roughly the number of digits in n and k. And it would just answer the question whether 2^n - 1 is a Mersenne prime. To prove that it is the k-th Mersenne prime, we would have to check 2^m - 1 for 1 <= m < n and prove that exactly k-1 of these are primes.
Currently the answer to the question is not known for k >= 44 and many 8-digit values n.
Bounded Factor.
Given number n, decide whether it has any proper factor less than k.
Is this a co-Np problem?
The problem is indeed a co-NP problem.
In order to see if a problem is in co-NP, you need to see if there is a polynomial verifier that could negate the question.
In this case, we could state the prime factors of n - one could easily check if they are indeed n's prime factors, as well as if one of the factors is smaller than k. If not, then there is no factor less than k!
Doing it this way, we prove that the problem is also in NP, because in the same way, we have a verifier that approves.