Python | sympy.divisor_sigma() method
Last Updated :
17 Sep, 2019
With the help of
sympy.divisor_sigma() method, we can find the divisor function
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:
from sympy.ntheory import divisor_sigma
n = 8
divisor_sigma_n = divisor_sigma(n)
print ( "divisor_sigma({}) = {} " . format (n, divisor_sigma_n))
|
Output:
divisor_sigma(8) = 15
Example #2:
from sympy.ntheory import divisor_sigma
n = 15
k = 2
divisor_sigma_n = divisor_sigma(n, k)
print ( "divisor_sigma({}, {}) = {} " . format (n, k, divisor_sigma_n))
|
Output:
divisor_sigma(15, 2) = 260
Share your thoughts in the comments
Please Login to comment...