Solution for problem 3

This commit is contained in:
David Doblas Jiménez 2021-06-05 14:42:04 +02:00
parent 94144c1d5a
commit c793c7e9dd

34
src/Python/Problem003.py Normal file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""
Created on 18 Mar 2017
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 3 of Project Euler
https://projecteuler.net/problem=3
"""
from utils import timeit
@timeit("Problem 3")
def compute():
"""
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
"""
target = 600851475143
ans = 2
while ans * ans < target:
while target % ans == 0:
target = target // ans
ans += 1
return target
if __name__ == "__main__":
print(f"Result for problem 3: {compute()}")