totient function by betaveros

r=range\x0d
def q():\x0d
 for x in r(2,10301):\x0d
  b=1\x0d
  for i in r(2,x):\x0d
   if x%i==0:b=0;break\x0d
  if b:yield x\x0d
z=set(q())\x0d
for n in r(10000,10301):\x0d
 s=n;t=1\x0d
 for p in z:\x0d
  if n%p==0:s*=p-1;t*=p\x0d
 print s/t\x0d

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page