当前位置: 代码迷 >> 综合 >> 杭电2161 Primes
  详细解决方案

杭电2161 Primes

热度:72   发布时间:2024-01-18 18:42:42.0

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;
}