4 solutions

  • 7
    @ 2024-6-14 10:25:22
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	cin>>n;
    	bool st=true; //默认为真 
    	if(n<2) //小于2的一定不是质数 
    	{
    		st=false;
    	}
    	for(int i=2;i<=sqrt(n);i++) //枚举小因子 
    	{
    		if(n%i==0) //存在因子 
    		{
    			st=false;
    		}
    	}
    	if(st) //符合要求 
    	{
    		cout<<"yes";
    	}
    	else
    	{
    		cout<<"no";
    	}
    	return 0;
    }
    
    • 2
      @ 2024-12-1 11:59:56
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	bool st=true;
      	int n;
      	cin>>n;
      	if(n<2)
      	{
      		st=false;
      	}
      	for(int i=2;i<=n/i;i++)
      	{
      		if(n%i==0)
      		{
      			st=false;
      		}
      	}
      	if(st==true)
      	{
      		cout<<"yes";
      	}
      	else
      	{
      		cout<<"no";
      	}
      	
          return 0;
      }
      
      • -2
        @ 2024-9-5 14:32:27
        #include<bits/stdc++.h>
        using namespace std;
        bool prime(int n)
        {
           bool st=true;
           for(int i=2;i<=sqrt(n);i++)
           {
              if(n%i==0)
              {
                 st=false;
              }
           }
           if(st)
           {
              return 1;
           }
           return 0;
        }
        int main()
        {
           int n;
           cin>>n;
           if(n==0||n==1)
           {
              cout<<"no";
           }
           else if(prime(n))
           {
              cout<<"yes";
           }
           else
           {
              cout<<"no";
           }
           return 0;
        }
        
        • -2
          @ 2024-6-14 19:47:37
          • #include<bits/stdc++.h>
            using namespace std;
            int main()
            {
            	int n;
            	cin>>n;
            	bool st=true; //默认为真 
            	if(n<2) //小于2的一定不是质数 
            	{
            		st=false;
            	}
            	for(int i=2;i<=sqrt(n);i++) //枚举小因子 
            	{
            		if(n%i==0) //存在因子 
            		{
            			st=false;
            		}
            	}
            	if(st) //符合要求 
            	{
            		cout<<"yes";
            	}
            	else
            	{
            		cout<<"no";
            	}
            	return 0;
            }
            

            Copy

          • 1

          质数

          1. 查看题目
          2. 递交
          3. 讨论
          4. 题解
          5. 文件
          6. 统计

          信息

          ID32时间1000ms内存256MiB难度7标签(无)递交数106已通过23上传者 jike1994

          状态

          开发

          支持

          1. 关于
          2. 联系我们
          3. 隐私
          4. 服务条款
          5. 版权申诉
          6. Language
          7. 兼容模式
          8. 主题
          9. 蜀ICP备
          • 1

          Information

          ID
          32
          Time
          1000ms
          Memory
          256MiB
          Difficulty
          1
          Tags
          (None)
          # Submissions
          279
          Accepted
          59
          Uploaded By