-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22.py
33 lines (31 loc) · 859 Bytes
/
22.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
#FINDS THE PRIME FACTORIZATION OF NUMBER
def primefactorization(x):
#COUNTER IS THE SAME AS FACTOR VALUE, TESTS
#ALL VALUES UNDER NUMBER, IF DIVISIBLE ADD TO
#PFACTORS LIST
counter = 2
pfactors = []
while not prime(x):
if prime(counter):
while x % counter == 0:
x = x // counter
pfactors.append(counter)
counter = counter + 1
if x != 1:
pfactors.append(x)
return ' x '.join(str(i) for i in pfactors)
#FUNCTION FINDS IF NUMBER IS PRIME
def prime(n):
if n != 1:
factors = []
for i in range(1, n):
if n % i == 0:
factors.append(i)
if len(factors) == 1:
return True
else:
return False
else:
return True
x = int(input('Enter num:'))
print(primefactorization(x))