January 7th, 2014, 07:34 PM
Print 10000000 primes
I can't understand this code.Anyone can help me :chomp: :chomp:
#define MAX 10000000
int IsPrimes(char* NT, int x)
return ((NT[x/8] >> (x%8))&1);
void Gan(char* NT, int x, int GiaTri)
NT[x/8] = NT[x/8] | (1<<(x%8));
NT[x/8] = NT[x/8] & (~(1<<(x%8)));
int Primes(int n)
int Dem = 0;
for (i=0;i<MAX;i++) Gan(NT,i,1);
if ( IsPrimes(NT,i) )
if (Dem==n) return i;
for (j=i<<1; j<MAX ;j+=i)
f = fopen("3.inp","rt");
January 7th, 2014, 10:46 PM
It's probably the algorithm, not the code, giving you trouble. Maybe someone reading this forum will recognize and explain it. Maybe you'll need to research prime number algorithms until you understand. At a glance, I'm clueless. Oh wait, I'll guess better than "clueless". It's a sieve method packing the table onto bits.
Last edited by b49P23TIvg; January 7th, 2014 at 10:49 PM.
[/code] are essential for python code and Makefiles!