Cod sursa(job #560514)

Utilizator lazarliviaLazar Livia lazarlivia Data 18 martie 2011 15:44:29
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include<climits>
#include<fstream.h>
#include<iostream.h>

#define max INT_MAX;
int nrz(int n)
{
 if(n==0) return 0;
 return n/5+nrz(n/5);
}
int main()
{

	int p,mij,st,dr,x;
	bool gasit;
	ifstream f("fact.in");
	ofstream g("fact.out");
	f>>p;
	st=0;
	dr=max;
if(p==0) g<<1; 
else

{ 


while(st<dr) 

{ 

mij=(st+dr)/2; 

x=nrz(mij); 

if(x==p) { 

 

while(nrz(mij)==p) mij--; 

g<<mij+1; gasit=true;break;} 

else

if(x<p) st=mij+1; 

else dr=mij-1; 

} 

 

if(!gasit) g<<-1; 

}
	
}