-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion3.py
More file actions
executable file
·33 lines (26 loc) · 807 Bytes
/
Question3.py
File metadata and controls
executable file
·33 lines (26 loc) · 807 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
#!/usr/bin/env python3.2
import math
def IsPrime(num):
if num < 1:
return False
for number in range(2, num):
#this function can be optimized by setting a break if number is
#greater than sqrt(num)
# print(num,number, num % number)
if num % number == 0:
return False
return True
def GetPrimeFactors(target, PrimeFactors):
if(IsPrime(target)):
PrimeFactors.add(target)
return
for number in range(2, target):
if target % number == 0:
GetPrimeFactors(target // number, PrimeFactors)
GetPrimeFactors(number, PrimeFactors)
break
Primes = set()
GetPrimeFactors(600851475143, Primes)
#GetPrimeFactors(2, Primes)
for nums in Primes:
print(nums)