-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeFactorizer.py
More file actions
36 lines (31 loc) · 1.11 KB
/
PrimeFactorizer.py
File metadata and controls
36 lines (31 loc) · 1.11 KB
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
#Get input num
InputNum = int(input("What is your number?\n"))
#Init some lists we use later, and a mutable copy of InputNum
PrimeNums = []
ModNum = InputNum
PrimeFacts = []
#The next loop gets us a handy list of prime numbers up to the user input number
print("The prime numbers up to " + str(InputNum) + " are...")
print("(for numbers over ~30,000 this can take some time to compute!)")
for num in range(2,InputNum + 1):
#Status helper, to let you know how much has been processed for large requests
if num % 1000 == 0:
print("Just processed "+ str(num))
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
PrimeNums.append(num)
print("The primes up to " + str(InputNum))
print(str(PrimeNums) + "\n")
while ModNum > 1:
if InputNum in PrimeNums:
print("That is a prime number you nerd!")
PrimeFacts = [ModNum]
break
for i in PrimeNums:
if ModNum % i == 0:
PrimeFacts.append(i)
ModNum = ModNum / i
print("The prime factorization of " + str(InputNum) + " is...\n" + str(PrimeFacts))