3 solutions

  • 2
    @ 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;
    }
    
    • 2
      @ 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;
      }
      
      • -1
        @ 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
        131
        Accepted
        47
        Uploaded By