解法一
✅ 完整代碼
評分結果(參考) : AC (3ms, 324KB)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, n;
cin >> x;
for(int i=2; i<=x; i++){
if(i!=2 && n!=0) cout << " * ";
n = 0;
while(x%i == 0){
x /= i;
n++;
}
if(n>1) cout << i << "^" << n;
else if(n==1) cout << i;
}
return 0;
}