Created
May 27, 2015 15:50
-
-
Save nathanPro/4db90894d538932c5e80 to your computer and use it in GitHub Desktop.
Why segfault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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