python - composite number decomposition

【Problem Description】

It is known from the fundamental theorem of mathematics that any non-prime integer greater than 1 (that is, a composite number) can be uniquely decomposed into the product of several prime numbers. Write a program to read a composite number from the console (the size of the composite number will not exceed the range represented by the int data type), and find the prime numbers that the composite number can be decomposed into.

【Input form】

Enter a composite number from the console.

【Output format】

On the standard output, output the decomposed prime numbers in ascending order, each prime number is separated by a space, and there can also be a space after the last integer.

【Input example】

12308760

【Example of output】

2 2 2 3 3 3 3 5 29 131

【Example description】

The input composite number is 12308760, and the product of prime numbers decomposed into it is: 2*2*2*3*3*3*3*5*29*131.

def fenjie(a):
    i = 2
    while a>=i:
        while a%i == 0:
            print(i,end=' ')
            a = a/i
        i = i+1
a = int(input())
fenjie(a)
        

Guess you like

Origin blog.csdn.net/qq_62315940/article/details/127817942