借助於sympy.sieve.totientrange()方法,我們可以生成給定範圍[a,b)的所有上位數字。它返回一個類型生成器對象,可以將其轉換為列表以進行進一步的操作。
用法: sieve.totientrange(a, b)
參數:
a - It denotes the start of the range. It is inclusive.
b - It denotes the end of the range. It is not inclusive.
返回: The method returns a type generator object.
範例1:
# import sympy
from sympy import sieve
# Use sieve.totientrange() method
totient_gen = sieve.totientrange(1, 10)
totient_list = list(totient_gen)
print("Totient numbers for the range of numbers [1, 10) : {}".format(totient_list))
輸出:
Totient numbers for the range of numbers [1, 10) : [1, 1, 2, 2, 4, 2, 6, 4, 6]
範例2:
# import sympy
from sympy import sieve
# Use sieve.totientrange() method
totient_gen = sieve.totientrange(8, 20)
totient_list = list(totient_gen)
print("Totient numbers for the range of numbers [8, 20) : {}".format(totient_list))
輸出:
Totient numbers for the range of numbers [8, 20) : [4, 6, 4, 10, 4, 12, 6, 8, 8, 16, 6, 18]
相關用法
- Python sympy.csc()用法及代碼示例
- Python sympy.cot()用法及代碼示例
- Python sympy.nP()用法及代碼示例
- Python sympy.crt()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python sympy.nC()用法及代碼示例
- Python sympy.cos()用法及代碼示例
- Python sympy.Pow()用法及代碼示例
- Python sympy.eye()用法及代碼示例
- Python sympy.tan()用法及代碼示例
- Python sympy.ones()用法及代碼示例
- Python sympy.sin()用法及代碼示例
- Python sympy.Add()用法及代碼示例
- Python sympy.S()用法及代碼示例
- Python sympy.has()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python sympy | sieve.totientrange() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。