Daniele Fucini 3b597a8845
Add more python solutions
Added python solutions for problems 11, 12, 13, 14, 15
2019-09-19 16:54:12 +02:00

37 lines
731 B
Python

#!/usr/bin/python3
import math
from timeit import default_timer
from projecteuler import is_prime
def max_prime_factor(num):
if is_prime(num):
return num
if num % 2 == 0:
return max_prime_factor(num // 2)
else:
limit = math.floor(math.sqrt(num)) + 1
for i in range(3, limit, 2):
if num % i == 0:
if is_prime(i):
return max_prime_factor(num // i)
def main():
start = default_timer()
res = max_prime_factor(600851475143)
end = default_timer()
print('Project Euler, Problem 3')
print('Answer: {}'.format(res))
print('Elapsed time: {:.9f} seconds'.format(end - start))
if __name__ == '__main__':
main()