You are viewing a single comment's thread. Return to all comments →
100 points. Implemented @leduckhai 's algorithm in Python 3.
sieve=[True]*10**3 for i in range(0,10**3,2): sieve[i]=False for j in range(3,int(10**3)+1,2): if sieve[j]: for k in range(j*2,10**3,j): sieve[k]=False sieve[1],sieve[2]=False,True def totient(n): m=1 ans=0 for i in range(1000): if sieve[i]: if m*i>=n: return m else: m=m*i ans+=i//(i-1) t=int(input().strip()) for _ in range(t): n=int(input().strip()) print(totient(n))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #69: Totient maximum
You are viewing a single comment's thread. Return to all comments →
100 points. Implemented @leduckhai 's algorithm in Python 3.