SPECIAL FACTORS
Ram loves playing with integers. He has a positive integer N. He wants to find special factors of the number. A factor is a number which exactly divides the given number. A factor is special if it is a prime number. Help ram by identifying all the special factors of the number.
INPUT : The input is a single line containing a positive integer N.
OUTPUT : The output should be a single line containing the space-separated prime factors in ascending order
EXPLANATION : In the example, the given number is 20.
the factors of 20 are 2, 4, 5, 10 Whereas the prime factors are 2, 5.
So, the output should be 2 5
sample input1 : 20
sample output1 : 2 5
sample input 2 : 45
sample output2 : 3 5
import math
n = int(input())
s = set()
def prime_fator(n):
while n % 2 == 0:
s.add(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while (n % i == 0):
s.add(i)
n = n / i
if n > 2:
s.add(int(n))
prime_fator(n)
print(*s)
Comments
Leave a comment