forked from majek/dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.py
62 lines (54 loc) · 1.06 KB
/
2.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
import array
import math
import bisect
def primes(limit):
p = array.array('L', [2])
for n in xrange(3, limit):
n_root = int(math.sqrt(n))
i = 0
while p[i] <= n_root:
if n % p[i] == 0:
break
i+=1
else:
p.append( n )
return p
def fib(limit):
f = array.array('L', [0, 1])
c = 0
while c < limit:
c = f[-2] + f[-1]
f.append( c )
return f
def factorize(n, p):
f = []
i = 0
n_root = int(math.sqrt(n))
while p[i] <= n_root:
if n % p[i] == 0:
f.append( p[i] )
i+=1
return f
x = 227000
print "primes"
p = primes(x*3)
print "fib"
f = fib(x*3)
def merge(a, b):
i = 0
j = 0
while i < len(a) and j < len(b):
if a[i] < b[j]:
i+=1
elif a[i] > b[j]:
j+=1
else:
return a[i]
return "not found"
pi = bisect.bisect_right(p, x)
fi = bisect.bisect_right(f, x)
print "merge"
r = merge(p[pi:], f[fi:])
f = factorize(r+1, p)
print f
print sum(f)