输入一个正整数,按照从小到大的顺序输出它的所有质因子(如180的质因子为2 2 3 3 5 )

def count_factors():
    n = int(input('input the num:'))
    num = n
    res = []
    while n > 1:
        for i in range(2, n+1):
            if n % i == 0:
                n = int(n/i)
                res.append(i)
                break
    print('{}={}'.format(num, res))

输出:

input the num:90
90=[2, 3, 3, 5]

猜你喜欢

转载自www.cnblogs.com/demo-deng/p/13204677.html