python质数因式分解
# 质数因式分解 import math x = int(input("请输入一个大于10的整数:")) primes = [p for p in range(2, x // 2 + 1) if 0 not in [p % d for d in range(2, int(math.sqrt(p)) + 1)]] factorList = [] y = x for i in primes: while y % i == 0: factorList.append(i) y = y // i if not factorList: print("%d=%d*%d" % (x, 1, x)) else: print(factorList) s = "*".join(map(lambda item: str(item), factorList)) print("%d=%s" % (x, s))
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/14821386.html