我自己猜是因為下面print的部分搞得太複雜,可是我想不到別的方法解決><求救!!
import sys
for s in sys.stdin:
p = int(s)
T = 0
factor = 0
list = []
for q in range(2,p+1):
t=0
while ( p%q == 0 ):
factor = 1
p = p/q
list.append(q)
t = list.count(q)
if factor == 1:
factor = 0
if t == 1 :
if T == 0 :
T =1
string = f'{q}'
else :
string = f'{string} * {q}'
else:
if T == 0 :
string = f'{q}^{t}'
T = 1
else:
string = f'{string} * {q}^{t}'
print(string)