Friday, November 14, 2025
HomeLanguagesPython | sympy.divisor_sigma() method

Python | sympy.divisor_sigma() method

With the help of sympy.divisor_sigma() method, we can find the divisor function \sigma_k(n) for positive integer n. divisor_sigma(n, k) is equal to the sum of all the divisors of n raised to the power of k or sum([x**k for x in divisors(n)]).

Syntax: divisor_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 divisors of n raised to the power of k.

Example #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


Output:

divisor_sigma(8) =  15 

Example #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


Output:

divisor_sigma(15, 2) =  260 
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS