Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rabiulcste
Created April 28, 2016 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rabiulcste/69dbc138cda983d0ed6b58e262cbd644 to your computer and use it in GitHub Desktop.
Save rabiulcste/69dbc138cda983d0ed6b58e262cbd644 to your computer and use it in GitHub Desktop.
#define MAX 1000001
char prime[MAX]; // 0 দিয়ে initialize করতে হবে
void seive( int n ) // n পর্যন্ত প্রাইম বের করব
{
int x = sqrt( n );
prime[0] = prime[1] = 1; // 0 এবং 1 প্রাইম না
for( int i = 4; i <= n; i += 2 ) // জোড় সংখ্যাগুলোকে বাদ দিয়ে দিব
prime[i] = 1;
for( int i = 3; i <= x; i += 2 ) {
if( prime[i] == 0 ) { // i যদি মৌলিক সংখ্যা হয় তাহলে 2i
for( int j = i+i; j <= n; j += i ) // থেকে শুরু করে i
prime[j] = 1; // এর সকল গুণিতককে বাদ দিয়ে দিব
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment