- 筛选法求素数
筛选法求素数(题解)
- 2023-11-5 10:39:05 @
#include <bits/stdc++.h>
using namespace std;
int main()
{
int s=0,n=100,a[101]={0};
//memset(a,0,sizeof(a));
for(int i=2;i<=sqrt(n);i++)
for(int j=2;j<=n/i;j++)
a[i*j]=1;
for(int i=2; i<=n; ++i)
{
if(a[i]==0)
{
cout<<i<<" ";
s++;
if(s%5==0)cout<<endl;
}
}
return 0;
}
0 comments
No comments so far...
Information
- ID
- 810
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 119
- Accepted
- 22
- Uploaded By