Follows 694.c (Total 26 lines):

/* @JUDGE_ID:4461XX 694 C */
/* A */
#include<math.h>
#include<stdio.h>
double check( double a , double limit )
{
	double time ;
	for( time=1.0 ; a!=1.0 ; time++ ){
		if( fmod( a , 2 ) ) a = 3.0 * a + 1.0 ;
		else a /= 2.0 ;
		if( a>limit ) break ;
	}
	return time ;
}
void main( void )
{
	double a , limit ;
	long i ;
	for( i=1 ; ; i++ ){
		scanf( "%lf %lf" , &a , &limit ) ;
		if( a<0.0 && limit<0.0 ) break ;
		printf( "Case %ld: A = %.0lf, limit = %.0lf, number of terms = %.0lf\n" ,
				i , a , limit , check( a , limit ) ) ;
	}
}
/* @END_OF_SOURCE_CODE */

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