题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607?tpId=37&tqId=21229&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
import math nums=[] N=int(input()) #chushu=range(2,N) def prime(num): chushu=range(2,int(math.sqrt(num))+1) if primeOrNot(num)==True: nums.append(num) return num else: for item in chushu: if num%item==0: nums.append(item) num=num//item return prime(num) def primeOrNot(num): if num<=0:return False if num in [1,2,3]: return True else: for i in range(2,int(math.sqrt(num))+1): if num%i==0: return False return True prime(N) nums.sort() #输出 for i in nums: print(i,end=' ')