题解 | #素数判定#
素数判定
https://www.nowcoder.com/practice/5fd9c28b1ce746dd99287a04d8fa9002
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <map> using namespace std; int main() { int n; while (scanf("%d", &n) != EOF) { if (n <= 0 || n == 1) { printf("no\n"); continue; } int i; for (i = 2; i <= n / 2; i++) { if (n % i == 0) { printf("no\n"); break; } } if (i > n / 2) { printf("yes\n"); } } return 0; }