2 solutions

  • 0
    @ 2023-10-28 13:08:55
    #include<iostream>
    using namespace std;
    int Judge(int n){
      /*if(n==1){
        return 0;
      }
      else*/
      //省去无效计算
      for(int i=2;i*i<=n;i++){
        if(n%i==0){
          return 0;
        }
      }
      return 1;
    }
    int main(){
      int n,sum=0;
      cin>>n;
      for(int i=2;i<=n;i++){
        sum+=Judge(i);
      }
      cout<<sum;
      return 0;
    }
    

    Information

    ID
    6767
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    306
    Accepted
    67
    Uploaded By