-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp003.py
More file actions
29 lines (23 loc) · 700 Bytes
/
p003.py
File metadata and controls
29 lines (23 loc) · 700 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
import sys
from math import sqrt, ceil
from euler_helpers import sieve
def main(n):
primes = sieve(int(ceil(sqrt(n))))
prime_factors = set()
d = n
print len(primes)
while d not in primes:
for prime in primes:
if d%prime==0:
prime_factors.add(prime)
d /= prime
prime_factors.add(d)
print 'Max prime factor of %d is %d' % (n,max(prime_factors))
if __name__=='__main__':
if len(sys.argv) < 2:
print 'Req int arg to calculate largest prime factor of'
raise Exception()
from time import time
start = time()
main(int(sys.argv[1]))
print 'Script took %d seconds' % (time()-start,)