#include <bits/stdc++.h>
using namespace std;
#define in long long
bool isPrime(int x) {
if(x == 1){
return false;
}
if (x == 2 || x == 3 || x == 5 || x == 7) {
return true;
}
if (x % 6 != 1 && x % 6 != 5) {
return false;
}
int tmp = sqrt(x);
for (int i = 5; i <= tmp; i += 6) {
if (x % i == 0 || x % (i + 2) == 0) {
return false;
}
}
return true;
}
in n,i = 2,ans;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n;
if (isPrime(n) == true){
cout << n << endl;
return 0;
}else{
while(n != 1 && isPrime(n) == false && i <= sqrt(n)){
if(isPrime(i) == false || n % i != 0){
i++;
continue;
}
else if(n % i == 0){
while(n % i == 0){
ans++;
n /= i;
}
cout << i;
if(ans > 1 && n == 1){
cout << "^" << ans << endl;
return 0;
}else if(ans > 1 && n > 1){
cout << "^" << ans << " * ";
}else{
cout << " * ";
}
ans = 0;
}
if (isPrime(n) == true){
cout << n << endl;
return 0;
}
}
}
return 0;
}
明明没错,我换成了
if(x==1)return 0;
for(int i=2;i*i<=x;i++)if(x%i==0)return 0;
return 1;
也是错的,程序显示10000000019是3的倍数