题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
def is_prime(x): if x == 1: return False for _i in range(2, 1+int(x**0.5)): if x % _i == 0: return False return True n = int(input()) res = [] i = 2 while i < 1+int(n**0.5): # 如果是因子,且是质数,则不断除以此数 if n % i == 0: # and is_prime(i): # 由于n已经对比i小的所有数取余过了,所以如果能对i取余为0,则i必是质数 while n % i == 0: n //= i res.append(str(i)) i += 1 if is_prime(n): res.append(str(n)) print(' '.join(res))