#10528. Find all prime numbers within n : Answer

C2024010 2024-08-15 13:13:14 2024-08-15 13:14:28

#include<bits/stdc++.h>

using namespace std;

int a[1000005]={0};

int main() {

int n;

cin>>n;

for(int i=2;i<=sqrt(n);i++){

	if(a[i]==0){

		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<<" ";

	}

}

return 0;

}