粗略的程式碼,大家可以想想怎麼改可以更簡潔又正確
prime= int(input())
k= int(prime)
t=0
cap=int(prime**0.5)+1
if k==1:
print ("1")
else:
for i in range (2,cap):
while (k%i==0):
t+=1
k=k//i
if k!=1:
if t==0:
pass
elif t==1:
print (str(i), end=" * ")
t=0
else:
print (str(i)+"^"+str(t), end=" * ")
t=0
if k==1:
if t==0:
pass
elif t==1:
print (str(i))
t=0
else:
print (str(i)+"^"+str(t))
t=0
if k==prime:
print(str(prime))
elif k!=1:
print (str(k))
else:
pass
請忽略本串,打錯串了