文章目录
- AcWing 726. 质数
- AC代码
AcWing 726. 质数
本题链接:AcWing 726. 质数
本博客给出本题截图:
AC代码
代码:
#include <iostream> using namespace std; int main() { int n, x; cin >> n; for (int i = 0; i < n; i ++) { cin >> x; bool is_prime = true; for (int j = 2; j * j <= x; j ++ ) { if (x % j == 0 ) { is_prime = false; break; } } if(is_prime) cout << x << " is prime" << endl; else cout << x << " is not prime" << endl; } return 0; }