Advertisement
makispaiktis

Project Euler 3 - Largest prime factor

Jul 23rd, 2020 (edited)
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 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. from math import sqrt
  6.  
  7. def findDivisorsOf(n):
  8.     divisors = list()
  9.     for i in range(2, int(sqrt(n) + 1)):
  10.         if n % i == 0:
  11.             divisors.append(i)
  12.     return divisors
  13.  
  14. def isPrime(n):
  15.     flag = True
  16.     for i in range(2, int(n/2)):
  17.         if n % i == 0:
  18.             flag = False
  19.             break
  20.     return flag
  21.  
  22.  
  23. # MAIN FUNCTION
  24. n = 600851475143
  25. divisors = findDivisorsOf(n)
  26. print(divisors)
  27. for i in range(len(divisors)):
  28.     print(divisors[i], findDivisorsOf(divisors[i]))
  29. print(int(486847/71))
  30. print(isPrime(6857))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement