Follows 371.c (Total 39 lines):

/* @JUDGE_ID:4461XX 371 C */
/* A */
#include<math.h>
#include<stdio.h>
void swap( double *a , double *b )
{
	double tmp ;
	tmp = *a ;
	*a = *b ;
	*b = tmp ;
}
double find_cycle( double num )
{
	double cycle ;
	for( cycle=1.0 ; ; cycle++ ){
		if( fmod( num , 2.0 ) ) num = 3 * num + 1 ;
		else num /= 2.0 ;
		if( num==1 ) break ;
	}
	return cycle ;
}
void main( void )
{
	double pre , lat , i , big , bigi , cycle ;
	while( scanf( "%lf %lf" , &pre , &lat ) == 2 ){
		if( !pre && !lat ) break ;
		if( pre > lat ) swap( &pre , &lat ) ;
		for( big=0 , i=pre ; i<=lat ; i++ ){
			cycle = find_cycle( i ) ;
			if( cycle > big ){
				big = cycle ;
				bigi = i ;
			}
		}
		printf( "Between %.0lf and %.0lf, %.0lf generates the longest sequence of %.0lf values.\n" ,
				pre , lat , bigi , big ) ;
	}
}
/* @END_OF_SOURCE_CODE */

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