Skip to content

Commit 359c593

Browse files
Merge pull request #132 from Harshal662/main
I have added a Python program to print prime factors of a given number
2 parents 78297cb + 5e51e9b commit 359c593

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

prime factors of a given number.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Python program to print prime factors
2+
3+
import math
4+
5+
6+
def primeFactors(n):
7+
8+
# Print the number of two\'s that divide n
9+
while n % 2 == 0:
10+
print (2),
11+
n = n / 2
12+
13+
# n must be odd at this point
14+
# so a skip of 2 ( i = i + 2) can be used
15+
for i in range(3,int(math.sqrt(n))+1,2):
16+
17+
# while i divides n , print i ad divide n
18+
while n % i== 0:
19+
print (i),
20+
n = n / i
21+
22+
23+
if n > 2:
24+
print (n)
25+
26+
27+
n = 315
28+
primeFactors(n)
29+

0 commit comments

Comments
 (0)