【发布时间】:2021-05-09 09:03:39
【问题描述】:
根据维基百科关于Euler's Totient Function 的描述,我编写了以下代码:
from math import gcd
def phi(n):
amount = 0
for k in range(1, n + 1):
if gcd(n, k) == 1:
amount += 1
return amount
它适用于小数字,但我想计算数字的 totient 函数,例如 n = 5692297035794675412610596123456169
有没有更好的方法来计算大输入的 Totoent 函数?
【问题讨论】:
-
你需要用到一些数学。蛮力是不够的。
-
如果这是 RSA 并且您的大数是 N = p*q 其中 p 和 q 是素数,那么有一种非常简单的方法可以计算 totient(N)。一点研究会帮助你。
-
大?多大?
factor(5692297035794675412610596123456169)和phi = (47-1) * (2819-1) * (65713-1) * (891551-1) * (57247819-1) * (12809677289-1) -
这能回答你的问题吗? Computing Eulers Totient Function
标签: python python-3.x cryptography