Follows 583.c (Total 48 lines):

/* @JUDGE_ID:4461XX 583 C */
/* A */
#include<stdio.h>
#include<math.h>
long prime[5000] ;
void make_prime( void )
{
	long i , k ;
	int j , yes ;
	for( i=2 , j=0 ; j<5000 ; i++ ){
		for( k=2 , yes=0 ; k<sqrt(i) ; k++ )
			if( !(i%k) ) yes = 1 ;
		if( !yes ) prime[j++] = i ;
	}
}
void run( long n , int time )
{
	int i ;
	for( i=0 ; n!=1 && i<5000 ; i++ ){
		while( !(n%prime[i]) ){
			n /= prime[i] ;
			if( time ) printf( " x %ld" , prime[i] ) ;
			else printf( " %ld" , prime[i] ) ;
			time++ ;
		}
	}
	if( n != 1 ){
		if( !time ) printf( " %ld" , n ) ;
		else printf( " x %ld" , n ) ;
	}
}
void main( void )
{
	long n ;
	make_prime() ;
	while( 1 ){
		scanf( "%ld" , &n ) ;
		if( !n ) break ;
		printf( "%ld =" , n ) ;
		if( n < 0 ){
			printf( " -1" ) ;
			run( -n , 1 ) ;
		}
		else run( n , 0 ) ;
		if( n == 1 ) printf( " %ld" , n ) ;
		putchar( '\n' ) ;
	}
}

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