Cod sursa(job #354742)

Utilizator alutzuAlexandru Stoica alutzu Data 9 octombrie 2009 12:09:50
Problema Factorial Scor 100
Compilator cpp Status done
Runda cautb1 Marime 0.52 kb
#include<cstdio>

int n ;

int zero ( int n ) 
{
	int r = 0 ;
	while (n)
		r += (n/=5) ;
	return r ;
}


int caut ( int x )
{
	int i , pas = (1<<30);
	--x;
	//for ( pas = 1 ; pas <= n ; pas <<= 1 ) ;
	for ( i = 0 ; pas ; pas >>= 1 )
		if ( zero ( i+pas ) <= x )
			i += pas ;
	if ( zero(i+1) != x+1 ) return -1 ;
	return i + 1 ;
}

int main ( )
{
	freopen ( "fact.in" , "r" , stdin  );
	freopen ( "fact.out" , "w" , stdout ) ;
	
	scanf ( "%d" , & n ) ;
	printf ( "%d" , caut ( n ) ) ;
	
	return 0 ;
}