python质因数分解

请编写程序,输入一个正整数 n(1<n<2^31),对其进行质因数分解,输出分解结果。
输入样例

6618848

输出样例

6618848 = 2^5 * 17 * 23^3

这跟判断是否是质数很像
不就是外层除数从小到大循环,除尽为止;
内层while一直循环,除到除不开为止

a=int(input())
print("{} = ".format(a),end='')
i=2
while a>1:
    count=0
    while a>1 and a%i==0:
        a//=i
        count+=1
    if count>0:
        print(i,end='')
        if count>1:
            print("^{}".format(count),end='')
        if a>1:
            print(" * ",end='')
    i+=1