#36590: python 77ms


ZhongWei (wei)

學校 : 桃園市私立復旦高級中學
編號 : 213177
來源 : [61.231.142.23]
最後登入時間 :
2024-11-10 13:34:47
a010. 因數分解 | From: [111.249.5.203] | 發表日期 : 2023-07-25 19:23

def factor(n):
    global factors
    for i in range(2, n+1):
        if n%i == 0:
            factors.append(i)
            factor(int(n/i))
            break
factors = []
factor(int(input()))
o = []
while factors != []:
    if factors.count(factors[0]) != 1: o.append(f'{factors[0]}^{factors.count(factors[0])}')
    else: o.append(str(factors[0]))
    factors = [x for x in factors if x != factors[0]]
print(' * '.join(o))

 

 
ZeroJudge Forum