Cod sursa(job #641532)

Utilizator costin7856Antonesi Florean Costin costin7856 Data 28 noiembrie 2011 19:18:44
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<fstream> 
using namespace std; 
long long p,m; 
//int i;  

int verifica(long long k) 
{     
	int nr=0;        
	while(k) 
		{           
			nr=nr+k/5; 
			k=k/5; 
		} 
		return nr; 
} 
void caut(long long st,long long dr,long long x) 
    
{ 
	long gasit=0; 
	while(st<=dr&&!gasit) 
	{ 
		m=(st+dr)/2; 
		if(verifica(m)==x) 
			gasit=1;              
			else
			if(x>verifica(m))         
			st=m+1; 
			else                           
			dr=m-1;  
       
	} 
	if(gasit==0) 
	m=-1;    
} 
	int main() 
{ 
	ifstream f("fact.in");    
	ofstream g("fact.out"); 
	f>>p; 
	caut(1,999999999,p);
	if(m!=-1) 
	{ 
		while(m) 
		{ 
			if(verifica(m)==p) 
			m--; 
			else
			break; 
		} 
		g<<m+1; 
	}             
	else
	g<<m; 
return 0; 
    
}