forked from Xctrunner/pe_class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p003.py
34 lines (28 loc) · 865 Bytes
/
p003.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import math
from utils import gen_primes
def get_prime_factors(number):
# root = math.floor(math.sqrt(number))
primes_up_to_number = gen_primes(number)
prime_factors = []
for prime in primes_up_to_number:
if number % prime == 0:
prime_factors.append(prime)
return sorted(prime_factors)
def get_prime_factors_2(number):
primes = [2]
factors = []
test_val = 3
while test_val < math.sqrt(number):
val_prime = True
for k in primes:
if test_val % k == 0:
val_prime = False
test_val += 2
if val_prime:
primes.append(test_val)
if number % test_val == 0:
factors.append(test_val)
number //= test_val
factors.append(number)
return factors
print(get_prime_factors_2(600851475143))