Skip to content

Instantly share code, notes, and snippets.

@nuit
Last active August 29, 2015 14:03
Show Gist options
  • Save nuit/0ea76c7f9d6081504ebd to your computer and use it in GitHub Desktop.
Save nuit/0ea76c7f9d6081504ebd to your computer and use it in GitHub Desktop.
Crivo de Eratóstenes, Função Totiente de Euler
from __future__ import division
def phi(i):
l=[]
n=1
multiples = set()
for p in range(2, i+1):
if p not in multiples:
multiples.update(range(p*p, i+1, p))
if i%p==0:
j=(p-1)/p
l.append(j)
for j in l:
n*=j
n=i*n
print n
phi(420)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment