HDU2161 http://acm.hdu.edu.cn/showproblem.php?pid=2161
AC代码:
#include <iostream>
using namespace std;
bool prime(int x) {
if(x == 1 || x == 2) return false;
for(int i = 2; i * i <= x; i++) {
if(x % i == 0) return false;
}
return true;
}
int main() {
int x;
int i = 1;
char ans;
while (cin >> x && x > 0) {
//cin >> x;
if (prime(x)) cout << i << ": " << "yes" << endl;
else cout << i <<": " << "no" << endl;
i++;
if (x == 0) return 0;
}
return 0;
}