Python | sympy.reduced_totient() method

With the help of sympy.reduced_totient() method, we can find the Carmichael reduced totient function or lambda(n) in SymPy. reduced_totient(n) or \lambda(n) is the smallest m > 0 such that k^m \equiv 1 \mod n for all k relatively prime to n.

Syntax: reduced_totient(n)

Parameter:
n – It denotes an integer.



Returns: Returns the smallest integer m > 0 such that km % n is equal to 1 for all k relatively prime to n.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

lambda(8) =  2 

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)) 

chevron_right


Output:

lambda(30) =  4


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.