-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0003.py
More file actions
executable file
·47 lines (40 loc) · 1.04 KB
/
0003.py
File metadata and controls
executable file
·47 lines (40 loc) · 1.04 KB
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 isprime(n):
i = 2
while i < n:
if n % i == 0:
return False
i += 1
return True
def genprimefactors(n):
i = 2
while i < n:
if n % i == 0:
if isprime(i):
yield i
i += 1
def test():
"""test isprime"""
if not isprime(3) or isprime(4) or not isprime(29) or isprime(30):
raise Exception('isprime broken')
# this is not a particularily exhaustive test
"""test genprimefactors"""
primefactors = [i for i in genprimefactors(13195)]
if [5, 7, 13, 29] != primefactors:
print primefactors
raise Exception('genprimefactors did not work')
# print 'All tests passed'
# largestprime = 1
# for i in genprimefactors(600851475143):
# print i
# largestprime = i
# print largestprime
def fn0():
number = 600851475143
divisor = 2;
while (number > 1):
if (0 == (number % divisor)):
number /= divisor
else:
divisor += 1
return divisor
solutions = [fn0]