L1-028 判断素数 分数 10

直接背素数板子

// 1'58"
#include <iostream>
using namespace std;
bool func(int n)
{
    if(n <= 1) return false;
    if(n == 2) return true;
    for(int i = 2; i <= n / i; ++ i)
        if(n % i == 0) return false;
    return true;
}
int main()
{
    int n;
    cin >> n;
    while(n --)
    {
        int tmp;
        cin >> tmp;
        if(func(tmp)) cout << "Yes";
        else cout << "No";
        if(n != 0) cout << endl;
    }
}
posted @ 2024-08-01 01:57  Frodnx  阅读(13)  评论(0)    收藏  举报