-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler3.py
More file actions
42 lines (31 loc) · 954 Bytes
/
euler3.py
File metadata and controls
42 lines (31 loc) · 954 Bytes
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
35
36
37
38
39
40
import math
#The prime factors of 13195 are 5, 7, 13 and 29.
#What is the largest prime factor of the number 600851475143 ?
initial = 65975
final = 600851475143
def factors(x):#find factors within range of input, highest factor cannot be larger than square root
regFactors = []
for b in range(2,int(math.sqrt(x))):
if x % b == 0:
regFactors.append(b)
return regFactors
def primeNumber(x):#Find prime number
if x<2:
return False
for i in range(2, int(math.sqrt(x)) + 1):
if x % i == 0:
return False
return True
def primeFactors(x):#Find if array of factors are prime
prime = []
for b in x:
if(primeNumber(b)):
prime.append(b)
return prime
def printFactors(x):#Print factors
for a in x:
print(a)
return
printFactors(primeFactors(factors(initial)))
print("")
printFactors(primeFactors(factors(final)))