Skip to content

Instantly share code, notes, and snippets.

@nathanPro
Created May 27, 2015 15:50
Show Gist options
  • Save nathanPro/4db90894d538932c5e80 to your computer and use it in GitHub Desktop.
Save nathanPro/4db90894d538932c5e80 to your computer and use it in GitHub Desktop.
Why segfault
int divs[MAX];
void slowSieve(int n)
{
memset(divs, 0, sizeof divs);
for( int i = 2; i <= n; i++ )
if( divs[i] == 0 ) // Achei primo
{
divs[i] = -1; // Fix, pois vou contar o primo em si
// Percorro todas as potências desse primo
for( int p = i; p <= n; p *=i )
// Conto todos os múltiplos deles
for( int m = p; m <= n; m += p )
divs[m]++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment