#include<bits/stdc++.h>
using namespace std;
int devide(int n){
int i;
for(i = 2; i < n && n % i; i++);
return !(i < n);
}
int main(){
long long n;
int i, c = 0, f = 0;
cin >> n;
for(i = 2; i <= n ; i++){
if(!devide(i))
continue;
if(n % i == 0){
if(f == 1)
cout << " * ";
cout << i;
f = 1;
while(n % i == 0){
n /= i;
c++;
}
if(c > 1)
cout << '^' << c;
c = 0;
}
}
}
if(!devide(i))
continue;
你的devide()是多餘的,刪掉就不會TLE了
ok!感恩XD