python0010

编写程序,输出一个给定正整数x(x>1)的质因子展开式。

num = int(input())
newnum = num
text = ""
counter = 2
while counter * counter <= newnum:
    if newnum % counter == 0:  # 判断是否能够整除2
        text = text + str(counter)  # 将质因子组合起来
        newnum = int(newnum / counter)
    else:
        counter += 1

if newnum != 1:  # 如果结果不为1,就加上目前的newnum质因子
    text = text + str(newnum)
if text == "" + str(newnum):  # 判断质因子就是其本身
    text = str(newnum)
print(str(num) + "=" + text)

 

posted @ 2024-05-22 08:38  新晋软工小白  阅读(13)  评论(0)    收藏  举报