Python| sympy.udivisors() 方法
借助sympy.udivisors()方法,我们可以默认按排序顺序找到给定数字的所有酉除数。
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.
示例 #1:
# import udivisors() method from sympy
from sympy.ntheory.factor_ import udivisors
n = 84
# Use udivisors() method
udivisors_n = udivisors(n)
print("The unitary divisors of {} : {}".format(n, udivisors_n))
输出:
The unitary divisors of 84 : [1, 3, 4, 7, 12, 21, 28, 84]
示例 #2:
# import udivisors() method from sympy
from sympy.ntheory.factor_ import udivisors
n = -210
# Use udivisors() method
udivisors_n = list(udivisors(n, generator = True))
print("The unitary divisors of {} : {}".format(n, udivisors_n))
输出:
The unitary divisors of -210 : [1, 2, 3, 6, 5, 10, 15, 30, 7, 14, 21, 42, 35, 70, 105, 210]