题解 | #素数判定#
素数判定
https://www.nowcoder.com/practice/5fd9c28b1ce746dd99287a04d8fa9002
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if(n == 1 || n == 0 || n < 0)return false; for(int i = 2; i <= sqrt(n); i++) { if(n % i ==0) return false; } return true; } int main(){ int n; while(cin >> n){ if(isPrime(n))cout << "yes" << endl; else cout << "no" << endl; } return 0; }