euler

git clone git://git.codymlewis.com/euler.git
Log | Files | Refs

commit 5abc233a17fde47a3943f2c7c53b43860e3f60fb
parent d4b5c67c0367f0f779ccb79f3ea0138ea68e7987
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Sat, 17 Nov 2018 19:35:43 +1100

Solution to problem 3

Diffstat:
AThree.py | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)

diff --git a/Three.py b/Three.py @@ -0,0 +1,23 @@ +import math +''' +The prime factors of 13195 are 5, 7, 13 and 29. + +What is the largest prime factor of the number 600851475143? +''' +def is_prime(n): + for i in range(2, int(math.sqrt(n) + 1)): + if (n % i) == 0: + return False + return True + + +def find_biggest_prime_factor(n): + for i in range(int(math.sqrt(n)), 1, -1): + if is_prime(i) and (n % i) == 0: + return i + return 1 + +if __name__ == "__main__": + LIMIT = 600_851_475_143 + print("Started calculating...") + print(f"The biggest prime factor of {LIMIT} is {find_biggest_prime_factor(LIMIT)}")