Skip to content

Instantly share code, notes, and snippets.

@nathanPro
Created May 27, 2015 20:25
Show Gist options
  • Save nathanPro/2f304eb0ad2d47633296 to your computer and use it in GitHub Desktop.
Save nathanPro/2f304eb0ad2d47633296 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
#define MAX 5000042
using namespace std;
int divs[MAX];
void slowSieve(int n)
{
for( int i = 0; i <= n; i++ )
divs[i] = 0;
for( int i = 2; i <= n; i++ )
if( divs[i] == 0 )
for( int p = i; p <= n; p *=i )
for( int m = p; m <= n; m += p )
divs[m]++;
}
int main()
{
int m;
scanf("%d", &m);
slowSieve(m);
for( int i = 0; i <= m; i++ )
if( divs[i] == 1 )
printf("%d ", i);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment