Advertisement
makispaiktis

Project Euler 3 - Largest even factor

Apr 11th, 2020 (edited)
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. '''
  2. The prime factors of 13195 are 5, 7, 13 and 29.
  3. What is the largest prime factor of the number 600851475143 ?
  4. '''
  5.  
  6. def isPrime(n):
  7.     flag = True
  8.     for i in range(2, int(n/2)):
  9.         if n % i == 0:
  10.             flag = False
  11.             break
  12.     return flag
  13.  
  14. # MAIN FUNCTION
  15. N = 600851475143
  16. factors = []
  17. for i in range(2, int(N/2)):
  18.     if N % i == 0 and isPrime(i):
  19.         factors.append(i)
  20.  
  21. print(factors[len(factors)-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement