測資#2一直TLE,還請各位大神幫忙,謝謝
x = int(input())
txt = ''
original = x
for i in range(2, x+1):
A = (x%i == 0 and x%(i**2) != 0)
if A == True:
x = x/i
txt += f"{i} * "
continue
B = (x%(i**2) == 0)
if B == True:
a = 2
x = x//(i**2)
while x%i == 0:
a += 1
x = x//i
txt += f"{i}^{a} * "
continue
if txt != '':
txt = txt[:-3]
elif txt == '':
txt += f"{original}"
print(txt)
https://zerojudge.tw/ShowThread?postid=22921&reply=0