编写程序,输出一个给定正整数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)
标签:int,text,counter,while,num,python0010 From: https://www.cnblogs.com/Lyh3012648079/p/18205357