Follows 107.c (Total 40 lines):

/* @JUDGE_ID:4461XX 107 C */
/* A */
#include<stdio.h>
#include<math.h>
long N ;
long find_x( long n , long k )
{
	long x ;
	for( N=1 ; ; N++ )
		for( x=1 ; (long)pow( N+1 , x )<=n ; x++ )
			if( (long)pow( N+1 , x ) == n && (long)pow( N , x ) == k ) return x ;
}
void unclean( long x )
{
	long i , cats=0 ;
	for( i=0 ; i<x ; i++ )
		cats += (long)pow( N , i ) ;
	printf( "%ld " , cats ) ;
}
void all_tall( long x )
{
	long i , j , tall=0 ;
	for( i=0 , j=x ; i<=x ; i++ , j-- )
		tall += (long)pow( N , i )*(long)pow( N+1 , j ) ;
	printf( "%ld\n" , tall ) ;
}
void main( void )
{
	long n , k , x ;
	while( 1 ){
		scanf( "%ld %ld" , &n , &k ) ;
		if( !n && !k ) break ;
		if( n==1 ) printf( "0 %ld\n" , k ) ;
		else{
			x = find_x( n , k ) ;
			unclean( x ) ;
			all_tall( x ) ;
		}
	}
}

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