Python| sympy.udivisor_sigma() 方法
借助sympy.udivisor_sigma()方法,我们可以计算酉除数函数对于任何正整数n 。 udivisor_sigma(n, k)等于n的所有酉除数之和的k次幂或sum([x**k for x in udivisors(n)]) 。
Syntax: udivisor_sigma(n, k)
Parameter:
n – It denotes an integer.
k – It denotes an integer(optional). Default for k is 1.
Returns: Returns the sum of all the unitary divisors of n raised to the power of k.
示例 #1:
# import udivisor_sigma() method from sympy
from sympy.ntheory.factor_ import udivisor_sigma
n = 12
# Use udivisor_sigma() method
udivisor_sigma_n = udivisor_sigma(n)
print("udivisor_sigma({}) = {} ".format(n, udivisor_sigma_n))
# 1 ^ 1 + 3 ^ 1 + 4 ^ 1 + 12 ^ 1 = 20
输出:
udivisor_sigma(12) = 20
示例 #2:
# import udivisor_sigma() method from sympy
from sympy.ntheory.factor_ import udivisor_sigma
n = 18
k = 2
# Use udivisor_sigma() method
udivisor_sigma_n = udivisor_sigma(n, k)
print("udivisor_sigma({}) = {} ".format(n, udivisor_sigma_n))
输出:
udivisor_sigma(18) = 410