#39259: python 解(AC)


yourongchen0720@gmail.com (陳宥融)

學校 : 不指定學校
編號 : 260729
來源 : [223.137.74.124]
最後登入時間 :
2024-06-01 19:37:05
a010. 因數分解 | From: [114.136.212.229] | 發表日期 : 2024-01-28 20:52

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