Skip to content

Create 素数筛#1

Open
tsandl wants to merge 1 commit intomasterfrom
tsxxx-patch-1
Open

Create 素数筛#1
tsandl wants to merge 1 commit intomasterfrom
tsxxx-patch-1

Conversation

@tsandl
Copy link
Owner

@tsandl tsandl commented Aug 16, 2018

#include
#include
using namespace std;
int main()
{
int n,i,j;
cin>>n;
int a[n];
for(i=0;i<=n;i++)//初始化数组
{
a[i]=i;
}
a[1]=0;
for(i=2;i<sqrt(n);i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]!=0&&a[j]%i==0)
{
a[j]=0;
}
}//以此判断是不是2的倍数,3,4 ......的倍数
}
for(i=1;i<=n;i++)
{
if(a[i]==0)
{
cout<<"No"<<endl;
}else cout<<"Yes"<<endl;
}
return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant