- 求出2-100之间的所有质数(素数)
 kunkun
- @ 2023-8-17 10:45:37
 
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int x)
{
    if(x==2)
    {
        return true;
    }
    if(x<2 || x%2==0)
    {
        return false;
    }
    for(int i=3; i<=sqrt(x);i+=2)
    {
        if(x%i==0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    for(int i=2;i<=100;i++)
    {
       if(isPrime(i)==true)
       {
         cout<<i<<" ";
       }
    }
    cout<<endl;
    return 0;
}
        1 comments
- 
  Carly LV 5 @ 2023-8-17 10:47:34
hehe
 
- 1
 
Information
- ID
 - 271
 - Time
 - 1000ms
 - Memory
 - 256MiB
 - Difficulty
 - 7
 - Tags
 - # Submissions
 - 228
 - Accepted
 - 40
 - Uploaded By