📜  Python| sympy.divisor_sigma() 方法

📅  最后修改于: 2022-05-13 01:55:51.687000             🧑  作者: Mango

Python| sympy.divisor_sigma() 方法

借助sympy.divisor_sigma()方法,我们可以找到除数函数\sigma_k(n)对于正整数ndivisor_sigma(n, k)等于n的所有除数的总和,以ksum([x**k for x in divisors(n)])的幂次幂计算。

示例 #1:

# import divisor_sigma() method from sympy
from sympy.ntheory import divisor_sigma
  
n = 8
  
# Use divisor_sigma() method 
divisor_sigma_n = divisor_sigma(n) 
      
print("divisor_sigma({}) =  {} ".format(n, divisor_sigma_n)) 
# 1 ^ 1 + 2 ^ 1 + 4 ^ 1 + 8 ^ 1 = 15

输出:

divisor_sigma(8) =  15 

示例 #2:

# import divisor_sigma() method from sympy
from sympy.ntheory import divisor_sigma
  
n = 15
k = 2
  
# Use divisor_sigma() method 
divisor_sigma_n = divisor_sigma(n, k) 
      
print("divisor_sigma({}, {}) =  {} ".format(n, k, divisor_sigma_n)) 
# 1 ^ 2 + 3 ^ 2 + 5 ^ 2 + 15 ^ 2 = 260

输出:

divisor_sigma(15, 2) =  260