#39330: (python)為何記憶區段錯誤?


peter26 (瑪卡巴卡)

學校 : 基隆市私立二信高級中學
編號 : 260646
來源 : [61.220.150.251]
最後登入時間 :
2024-11-14 14:50:31
a010. 因數分解 | From: [111.248.250.134] | 發表日期 : 2024-02-07 01:55

import sys  
sys.setrecursionlimit(100000)
def yeah(m = {}, num = 0, i = 2):
    if i > num:
        return m
    if num % i != 0:
        return yeah(m = m, num = num, i = i+1)
    mi = False
    try:
        if m[i]:
            mi = True
    except:
        pass
    if mi:
        m[i] += 1
    else:
        m[i] = 1
    return yeah(m = m, num = num//i, i = i)
DICT = yeah(num = int(input()))
key_array = list(DICT.keys())
for key in key_array:
    if DICT[key] == 1:
        print(key, end = '')
    else:
        print(f'{key}^{DICT[key]}', end = '')
    if key_array.index(key) != len(key_array) - 1:
        print(' * ', end = '')
 
ZeroJudge Forum