pythonExample100/JCP014.py

26 lines
674 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序14】
题目将一个正整数分解质因数。例如输入90,打印出90=2*3*3*5。
程序分析对n进行分解质因数应先找到一个最小的质数k然后按下述步骤完成
(1)如果这个质数恰等于n则说明分解质因数的过程已经结束打印出即可。
(2)如果n<>k但n能被k整除则应打印出k的值并用n除以k的商,作为新的正整数你n,
 重复执行第一步。
(3)如果n不能被k整除则用k+1作为k的值,重复执行第一步。
2.程序源代码:
'''
from sys import stdout
n = int(raw_input("input number:\n"))
print "n = %d" % n
for i in range(2,n + 1):
while n != i:
if n % i == 0:
stdout.write(str(i))
stdout.write("*")
n = n / i
else:
break
print "%d" % n