試了很多還是一直2s...請問有人可以給我點提示嗎??謝謝
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x;
do {
cin >> x;
int a = sqrt(x);
bool prime[a];
int b = 0;
for (int i = 0; i < a + 1; i++)
prime[i] = true;
prime[0] = prime[1] = false;
for (int i = 2; i < a + 1; i++) {
if (prime[i]) {
for (int j = i + i; j < a + 1; j += i)
prime[j] = false;
if (x % i == 0) { b = 1; break; }
}
}
(b == 0) ? cout << "質數\n" : cout << "非質數\n";
} while (x >= 2 && x <= 2147483647);
return 0;
}