Python| sympy.totient() 方法
借助sympy.totient()方法,我们可以找到给定整数的 Euler totient函数或 phi(n)。欧拉函数是小于或等于给定整数且与其互质的正整数的个数。换句话说,它是1 <= k <= n范围内的整数k的数量,其中最大公约数gcd(n, k)等于1 。
Syntax: totient(n)
Parameter:
n – It denotes an integer.
Returns: Returns the number of integers less than or equal to that integer n that are relatively prime to it.
示例 #1:
# import totient() method from sympy
from sympy.ntheory.factor_ import totient
n = 24
# Use totient() method
totient_n = totient(n)
print("phi({}) = {} ".format(n, totient_n)) # 1 5 7 11 13 17 19 23
输出:
phi(24) = 8
示例 #2:
# import totient() method from sympy
from sympy.ntheory.factor_ import totient
n = 19
# Use totient() method
totient_n = totient(n)
print("phi({}) = {} ".format(n, totient_n))
输出:
phi(19) = 18
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。