當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python sympy.reduced_totient()用法及代碼示例

借助於sympy.reduced_totient()方法,我們可以在SymPy中找到Carmichael簡化的totient函數或lambda(n)。 reduced_totient(n)或\lambda(n)是最小的m> 0這樣k^m \equiv 1 \mod n對所有人ķ相對於ñ

用法: reduced_totient(n)

參數:
n - 它表示一個整數。


返回:返回最小整數m> 0,使km對於相對於n的所有k,%n等於1。

範例1:

# import reduced_totient() method from sympy 
from sympy.ntheory import reduced_totient 
  
n = 8
  
# Use reduced_totient() method  
reduced_totient_n = reduced_totient(n)  
      
print("lambda({}) =  {} ".format(n, reduced_totient_n))  
# 1 ^ 2 = 1 (mod 8), 3 ^ 2 = 9 = 1 (mod 8), 
# 5 ^ 2 = 25 = 1 (mod 8) and 7 ^ 2 = 49 = 1 (mod 8)

輸出:

lambda(8) =  2 

範例2:

# import reduced_totient() method from sympy 
from sympy.ntheory import reduced_totient 
  
n = 30
  
# Use reduced_totient() method  
reduced_totient_n = reduced_totient(n)  
      
print("lambda({}) =  {} ".format(n, reduced_totient_n)) 

輸出:

lambda(30) =  4


相關用法


注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python | sympy.reduced_totient() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。