【发布时间】:2016-02-09 07:38:15
【问题描述】:
This paper 解释了 Pollard 的 p-1 分解算法。当找到的因子等于我们返回并更改“a”的输入时,我无法理解这种情况(基本上是上述论文中的第 2 页第 2 点)。
- 为什么我们要返回并增加“a”?
- 为什么我们不继续增加阶乘?是因为我们不断进入我们已经看到的同一个周期吗?
-
我可以使用相同的算法获得所有因子吗?如 49000 = 2^3 * 5^3 * 7^2。目前我只得到 7 和 7000。也许我可以递归地使用这个 get_factor() 函数,但我想知道基本情况。
def gcd(a, b): if not b: return a return gcd(b, a%b) def get_factor(input): a = 2 for factorial in range(2, input-1): '''we are not calculating factorial as anyway we need to find out the gcd with n so we do mod n and we also use previously calculate factorial''' a = a**factorial % input factor = gcd(a - 1, input) if factor == 1: continue elif factor == input: a += 1 elif factor > 1: return factor n = 10001077 p = get_factor(n) q = n/p print("factors of", n, "are", p, "and", q)
【问题讨论】:
标签: prime-factoring factorization