input :- The input line 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
if input1 is : 20
then output1 is: 2 5
if input 2 is : 45
then output2 is :- 3 5
def get_factors(x):
L = []
q = 2
while x >= q:
if x%q == 0:
L.append(q)
while x%q == 0:
x = x // q
if q == 2:
q = 3
else:
q = q + 2
return L
def main():
x = int(input())
L = get_factors(x)
for q in L:
print(q, end=' ')
print()
if __name__ == '__main__':
main()
Comments
Leave a comment