-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler3.py
More file actions
30 lines (24 loc) · 769 Bytes
/
euler3.py
File metadata and controls
30 lines (24 loc) · 769 Bytes
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
"""euler question 3"""
import math
def is_prime(num):
"""logic test to find a prime number"""
if num <= 3:
return num >= 2
if num % 2 == 0 or num % 3 == 0:
return False
for i in xrange(5, int(math.ceil(math.sqrt(num))), 6):
if num % i == 0 or num % (i + 2) == 0:
return False
return True
def largest_prime(num):
"""finds the largest prime number"""
if int(math.ceil(math.sqrt(num))) % 2 == 0:
end = int(math.ceil(math.sqrt(num))) + 1
else:
end = int(math.ceil(math.sqrt(num)))
print end
for i in reversed(xrange(3, end, 2)):
if num % i == 0:
if is_prime(i):
return i
print largest_prime(600851475143)