Follows 350.c (Total 40 lines):

/* @JUDGE_ID:4461XX 350 C */
/* A */
#include<stdio.h>
struct hash{
	char used ;
	long cycle ;
}hash[10000] ;
void initial_hash( void )
{
	int i ;
	for( i=0 ; i<10000 ; i++ )
		hash[i].used = hash[i].cycle = 0 ;
}
void print( long time , long cycle , long l )
{
	printf( "Case %ld: %ld\n" , time , cycle-hash[l].cycle ) ;
}
void main( void )
{
	long z , i , m  , l , time , cycle ;
	for( time=1 ; ; time++ ){
		scanf( "%ld %ld %ld %ld" , &z , &i, &m , &l ) ;
		if( !z && !i && !m && !l ) break ;
		initial_hash() ;
		hash[l].used = 1 ;
		hash[l].cycle = 0 ;
		for( cycle=1 ; ; cycle++ ){
			l = ( z * l + i ) % m ;
			if( hash[l].used ){
				print( time , cycle , l ) ;
				break ;
			}
			else{
				hash[l].used = 1 ;
				hash[l].cycle = cycle ;
			}
		}
	}
}
/* @END_OF_SOURCE_CODE */

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