Answer to Question #282030 in Python for saikalyan reddy

Question #282030

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


1
Expert's answer
2021-12-22T14:18:33-0500
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS