Skip to content

Create 素数筛 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Create 素数筛 #1

wants to merge 1 commit into from

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