Skip to content

Instantly share code, notes, and snippets.

@sinmaplewing
Created November 2, 2011 14:20
Show Gist options
  • Save sinmaplewing/1333750 to your computer and use it in GitHub Desktop.
Save sinmaplewing/1333750 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<math.h>
#define ERROR 0.000000001
int main()
{
int N;
while( scanf( "%d", &N ) != EOF && N != 0 )
{
int i;
int prime_count[105] = {0};
for( i = N ; i >= 2 ; i-- )
{
int temp = i;
int j;
int sqrt_i = (int)( sqrt( (double)temp ) + ERROR );
for( j = 2 ; j <= sqrt_i ; j++ )
while( !(temp % j) )
{
prime_count[j]++;
temp /= j;
}
if( temp > 1 )
prime_count[temp]++;
}
printf( "%3d! =", N );
int count = 0;
for( i = 2 ; i <= N ; i++ )
{
if( prime_count[i] )
{
if( !(count % 15) && count != 0 )
printf( "\n " );
count++;
printf( "%3d", prime_count[i] );
}
}
printf( "\n" );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment