How many ways can you think of , for writing a program that gives Euler's Totient function ?
Here are 2 that use 2 different definitions of the phi function.
This program uses the basic definition of , which is
is the number of natural numbers less than , which are coprime to
1 2 3 4 5 6 7 8
Now as we took ,
we actually took them coprime, counting all of them and getting them in the list
len(li) which is length of the list, the number of natural numbers less than , which are coprime to .
This program uses a formula by using primes,
For a natural number , we can define as
or in other words, if , then
1 2 3 4 5 6 7 8 9 10
Hence for every prime number dividing , the program transforms , at the end resulting into the value
Anyone knowing any other method is welcome to post it :)