素数判断

  1. 通过总量判断
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int cnt = 0;   // 统计因数个数

    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            cnt++;
        }
    }

    if (cnt == 2) {
        cout << "Y" << endl;
    } else {
        cout << "N" << endl;
    }
}