借助於sympy.divisor_count()方法,我們可以計算給定整數的除數。
用法: divisor_count(n, modulus=1)
參數:
n – 它表示一個整數。
modulus – 默認情況下設置為1。如果模量不為1,則僅對可被模數整除的那些計數。
返回值:返回給定數字的除數計數。
示例1:
# import divisor_count() method from sympy
from sympy import divisor_count
n = 84
# Use divisor_count() method
divisor_count_n = divisor_count(n)
print("The number of divisors of {} : {}".format(n, divisor_count_n))
輸出:
The number of divisors of 84 : 12
示例2:
# import divisor_count() method from sympy
from sympy import divisor_count
n = 12
# Use divisor_count() method
divisor_count_n = divisor_count(n, modulus = 2)
print("The number of divisors of {} : {}".format(n, divisor_count_n))
輸出:
The number of divisors of 12 : 4
相關用法
- Python os.dup()用法及代碼示例
- Python next()用法及代碼示例
- Python set()用法及代碼示例
- Python PIL putalpha()用法及代碼示例
- Python os.isatty()用法及代碼示例
- Python os.ttyname()用法及代碼示例
- Python os.pread()用法及代碼示例
- Python os.fsencode()用法及代碼示例
- Python os.system()用法及代碼示例
- Python os.getloadavg()用法及代碼示例
- Python os.get_inheritable()用法及代碼示例
- Python PIL getpalette()用法及代碼示例
- Python PIL tobytes()用法及代碼示例
- Python PIL getcolors()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python | sympy.divisor_count() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。