-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem3
More file actions
executable file
·37 lines (26 loc) · 806 Bytes
/
problem3
File metadata and controls
executable file
·37 lines (26 loc) · 806 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
31
32
33
34
35
36
37
#!/usr/bin/python
# problem: The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
# prime factors of x are the sum of the prime factors of its multiples
# how to detect if a number is prime quickly?
import sys
from math import sqrt
# my first try using trial division
input = 600851475143
def main():
max = 1
print factors(input)
for factor in factors(input):
if(len(factors(factor)) == 0 and factor > max):
max = factor
print max
def factors(value):
maxTrialValue = int(sqrt(value))
results = []
for candidate in range(2, maxTrialValue + 1):
if (value % candidate == 0):
results.append(candidate)
results.append(value / candidate)
return results
if __name__ == "__main__":
main()