文章

119

粉丝

0

获赞

146

访问

8.8k

头像
素数判定 - 哈尔滨工业大学 题解:
P1355 哈尔滨工业大学机试
发布于2026年2月3日 19:29
阅读数 47

#include<iostream>
using namespace std;

int n;

bool check(int n)
{
    if(n<=1)
    return false;
    if(n==2)
    return true;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}

int main()
{
    while(cin>>n)
    {
       if(check(n))
       cout<<"yes"<<endl;
       else
       cout<<"no"<<endl;
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发