5 solutions

  • 2
    @ 2026-8-13 14:34:58
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a,b;
    	cin>>a>>b;
    	for(int i=a;i<=b;i++)//枚举a~b之间的所有数
    	{
    		int cnt=0;
    		for(int j=1;j<=i;j++)//枚举1~i之间的所有数
    		{
    			if(i%j==0)//j是否为i的因数
    			{
    				cnt++;
    			}
    		}
    		if(cnt==2)//为质数(素数)
    		{
    			cout<<i<<endl;
    		}
    	}
    	return 0; 
    }
    
    • @ 2026-9-27 9:36:35

      神了,学生还发备注

  • 1
    @ 2025-7-7 10:32:01
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a,b;
        cin>>a>>b;
        for(int i=a;i<=b;i++)
        {
            int st=0;
            for(int j=2;j<=sqrt(i);j++)
            {
                if(i%j==0)
                {
                    st=1;
                }
            }
            if(st==0) cout<<i<<endl;
        }
        return 0;
    }
    
    • 0
      @ 2024-10-27 16:26:40
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          int a,b;
          cin>>a>>b;
          for(int i=a;i<=b;i++)
          {
              int st=0;
              for(int j=2;j<=sqrt(i);j++)
              {
                  if(i%j==0)
                  {
                      st=1;
                  }
              }
              if(st==0) cout<<i<<endl;
          }
          return 0;
      }
      
      • 0
        @ 2024-6-21 18:56:10
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            int a,b;
            cin>>a>>b;
            for(int i=a;i<=b;i++)
            {
                int st=0;
                for(int j=2;j<=sqrt(i);j++)
                {
                    if(i%j==0)
                    {
                        st=1;
                    }
                }
                if(st==0) cout<<i<<endl;
            }
            return 0;
        }
        
        • -3
          @ 2024-12-28 14:09:12

          可行的新方法

          #include<bits/stdc++.h>
          using namespace std;
          int main()
          {
                int a,b;
                cin>>a>>b;
                for(int i=a;i<=b;i++)
                {
                      int t=0;
                      for(int j=1;j<=i;j++)
                      {
                            if(i%j==0)
                            {
                                  t++;
                            }
                      }
                      if(t==2)//质数只有2个因数
                      {
                            cout<<i<<endl;
                      }
                }
                return 0;
          }
          
          • 1

          Information

          ID
          55
          Time
          1000ms
          Memory
          256MiB
          Difficulty
          3
          Tags
          (None)
          # Submissions
          251
          Accepted
          95
          Uploaded By