Efficient algorithm for finding a common divisor closest to some value?

前端 未结 4 1008
终归单人心
终归单人心 2021-01-11 20:12

I have two numbers, x1 and x2. For a number y, I want to calculate the common divisor of x1 and x2 as close

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-11 20:33

    I believe that there is no known efficient (polynomial-time) algorithm for this problem because there is a polynomial-time reduction from integer factorization to this problem. Since there is no known polynomial-time algorithm for integer factorization, there cannot be a known algortihm for your problem either, since otherwise we would indeed have a polynomial-time algorithm for integer factorization.

    To see how this works, suppose you have a number n that you'd like to factor. Now, using whatever algorithm you'd like, find the common factor of n and n closest to √n. Since no nontrivial divisor of n can be greater than √n, this finds either (1) the largest integer that divides n, or (2) the number 1 if n is prime. You can then divide n by this number and repeat to produce all the factors of n. Since n can have at most O(log n) factors, this requires at most polynomially many iterations of the solver for your problem, so we have a polynomial-time reduction from integer factorization to this problem. As mentioned above, this means that, at least in the open literature, there is no known efficient classical algorithm for solving this problem. One might exist, but it would be a really hugely important result.

    Sorry for the negative answer, and hope this helps!

提交回复
热议问题