题解 | 质数因子
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
from math import sqrt
def factor(num: int) -> list:
p = list()
while num % 2 == 0:
p.append(2)
num //= 2
for i in range(3, int(sqrt(num)) + 1, 2):
while num % i == 0:
p.append(i)
num //= i
if num > 1:
p.append(num)
return p
n = int(input())
p = factor(n)
for pi in p:
print(pi, sep=' ', end=' ')
查看29道真题和解析