- 题解
qq
- 2023-10-21 16:03:50 @
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int s=0,n=100,a[101]={0};
//memset(a,0,sizeof(a)); //数组初始化为0,假设所有都是素数,再把非素数排除
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...