Follows 106.c (Total 53 lines):

/* @JUDGE_ID:4461XX 106 C */
/* A */
#include<stdio.h>
#include<math.h>
#define MAX 1000000

int used[MAX+1] ;
void swap( int *a , int *b )
{
	int temp ;
	temp = *a ;
	*a = *b ;
	*b = temp ;
}
int gcd( int a , int b )
{
	if( a<b ) swap( &a , &b ) ;
	while( b ){
		a %= b ;
		swap( &a , &b ) ;
	}

	return a ;
}
int main( void )
{
	int n , x , y , a , b , c ;
	int really , notused , i ;

	while( scanf( "%d" , &n )==1 ){
		for( x=1 ; x<=n ; x++ ) used[x] = 0 ; /* initial */
		for( x=(int)sqrt( n )+1,really=0 ; x>1 ; x-- )
			for( y=x-1 ; y>0 ; y-- ){
				a = (int)pow( x , 2.0 ) + (int)pow( y , 2.0 ) ;
				b = (int)pow( x , 2.0 ) - (int)pow( y , 2.0 ) ;
				c = 2 * x * y ;
				if( a<=n && b<=n && c<=n )
					if( gcd( a , b )==1 &&
						gcd( b , c )==1 &&
						gcd( c , a )==1 ){
						really++ ;
						for( i=1 ; a*i<=n&&b*i<=n&&c*i<=n ; i++ )
							used[a*i] = used[b*i] = used[c*i] = 1 ;
					}
			}
		for( notused=0,i=1 ; i<=n ; i++ )
			if( !used[i] ) notused++ ;
		printf( "%d %d\n" , really , notused ) ;
	}

	return 0 ;
}
/* @END_OF_SOURCE_CODE */

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com