引用库
主函数
from factorization import factorization
def EulerTotientFunction(p: int):
try:
int(p)
if p < 2:
return -1
else:
ret = p
factorDict = factorization(p)
for k in factorDict:
k = int(k)
ret = ret*(k-1)//k
return ret
except Exception as e:
print(e)
return -1
测试
print(EulerTotientFunction(2))
print(EulerTotientFunction(3))
print(EulerTotientFunction(4))
print(EulerTotientFunction(6))
print(EulerTotientFunction(12))
测试结果
1
2
2
2
4