-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler124.py
66 lines (55 loc) · 1021 Bytes
/
euler124.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# trying euler 124. HM of rad n
rad = []
for i in xrange(0,100000,1):
rad.append(0)
print len(rad)
def sieve(n):
j=2
k=0
yolist=[1]*n
while j**2<n:
k=j**2
while k<n:
yolist[k]=0
k += j
j += 1
while yolist[j]==0:
j += 1
return yolist
# 1 = true,0 = false
def primelist(l,u):
i = l
ans=[]
sieve_n=sieve(u + 1)
if i == 1:
i = 2
while i <= u:
if sieve_n[i]:
ans.append(i)
i += 1
return ans
plist = primelist(1,100000)
print "Primes ready, starting rad."
# now fill rad.
rad[0] = 1
for elem in plist:
rad[elem-1] = elem
for i in xrange(3,100000,1):
if rad[i] == 0:
# find the first prime divisible by i
x = 0
j = i+1
while not j%plist[x] == 0:
x += 1
# found. plist[x] divides i
p1 = plist[x]
if (j/p1)%p1 == 0:
rad[i] = rad[j/p1 - 1]
else:
rad[i] = rad[j/p1 - 1]*p1
print "All rads done."
print rad[7]
print rad[503]
print rad[10000]
# traverse rad, sort all.
# sorting main problem!!