-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patha.py
47 lines (39 loc) · 940 Bytes
/
a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#def find_factor(n) :
# for i in xrange(2, int(n**0.5 + 1)) :
# if n % i == 0 :
# return i
# return n
#def find_factors(n) :
# factors = []
# while n != 1 :
# fac = find_factor(n)
# if fac not in factors :
# factors.append(fac)
# n /= fac
# return factors
import psyco
psyco.full()
import primes
pt = primes.primeTable(1000*1000)
def find_factors(n) :
factors = set()
while pt[n] != 1 :
factors.add(pt[n])
n /= pt[n]
factors.add(n)
return factors
def totient(n) :
num, denom = 1, 1
for factor in find_factors(n) :
num *= (factor - 1)
denom *= factor
return (n * num) / denom
import datetime
s = datetime.datetime.utcnow()
pt = primes.primeTable(1000*1000)
e = datetime.datetime.utcnow()
print e - s
s = datetime.datetime.utcnow()
print sum((i-1 if pt[i] == 1 else totient(i)) for i in xrange(2, 1000001))
e = datetime.datetime.utcnow()
print e - s