-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime_factorization.py
More file actions
38 lines (34 loc) · 887 Bytes
/
prime_factorization.py
File metadata and controls
38 lines (34 loc) · 887 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
# Program to carry out the Prime Factorization Process.
# It takes an integer no as the Input and find the Prime factor of the given No.
#author@Pratik Narode(pratiknarode143@gmail.com)
a=list()
factor=list()
def prime():
for i in range(2,50):
flag=0
for j in range(2,(i/2)+1):
if i%j==0:
flag=1
break
if flag==0:
a.append(i)
return
def primefactor(n):
while n!=1:
for i in range(len(a)):
if n%a[i]==0:
factor.append(a[i])
n=n/a[i]
break
fac=""
for i in range(len(factor)-1):
fac+=str(factor[i])+"x"
i+=1
fac+=str(factor[i])
print "The Prime Factors are:",fac
return
if __name__=="__main__":
prime()
print "Enter the No to Prime Factorize:"
n=int(raw_input())
primefactor(n)