Python | sympy.udivisors() method
Last Updated :
28 Aug, 2019
With the help of sympy.udivisors() method, we can find all the unitary divisors of a given number in sorted order by default.
Syntax: udivisors(n, generator=False)
Parameter:
n – It denotes an integer.
generator – If generator is True an unordered generator object is returned, otherwise it returns a sorted list of unitary divisors. It is False by default.
Returns: Returns a list of all the unitary divisors of the given integer.
Example #1:
from sympy.ntheory.factor_ import udivisors
n = 84
udivisors_n = udivisors(n)
print ( "The unitary divisors of {} : {}" . format (n, udivisors_n))
|
Output:
The unitary divisors of 84 : [1, 3, 4, 7, 12, 21, 28, 84]
Example #2:
from sympy.ntheory.factor_ import udivisors
n = - 210
udivisors_n = list (udivisors(n, generator = True ))
print ( "The unitary divisors of {} : {}" . format (n, udivisors_n))
|
Output:
The unitary divisors of -210 : [1, 2, 3, 6, 5, 10, 15, 30, 7, 14, 21, 42, 35, 70, 105, 210]
Share your thoughts in the comments
Please Login to comment...