题解 | #质数因子#
质数因子
http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
'''
方法一:
2|________180_________2|_____90________
3|___45_______
3|__15_____
5|__5__
1
'''
i = int(input())
tem = []
for k in range(2,int(i**0.5)+1):
while i%k == 0:
tem.append(k)
i = i//k
if i != 1:
tem.append(i)
print(' '.join(map(str,sorted(tem))))
'''
方法二
2|________180_________2|_____90________
3|___45_______
3|__15_____
5
函数迭代法:
def QZS(n):
for k in range(2,int(n**0.5)+1):##int直接抹去小数,不是四舍五入
if n % k == 0:
print(k, end=' ')
n = n//k
QZS(n)
break
if k == int(n**0.5) and n % k != 0:
print(n,end=' ')
QZS(a)
'''
【牛客站内】华为机试题—简单 文章被收录于专栏
【牛客站内】华为机试题练习记录