Home > Software design >  [python]Euler phi function with phi(n)=16
[python]Euler phi function with phi(n)=16

Time:11-03

i want to find the number n such that phi(n)=16. I code this.

from math import gcd
def phi(n):
    value=0
    for k in range(1,n 1):
        if gcd(n,k)==1:
            value =1
    return value

i=1
while phi(i)!=16:
    i =1
print(i)

it return 17 but phi(32)=16. how can I do this?

CodePudding user response:

from math import gcd
def phi(n):
    value=0
    for k in range(1,n 1):
        if gcd(n,k)==1:
            value =1
    return value

i=1
while True:       #infinite loop
    if phi(i)==16:
        print(i)
    i =1

Note that this is an infinite loop. It will keep running even after all phi(i)==16 values are found

  • Related