Cod sursa(job #427868)

Utilizator CeachiCeachi Bogdan Ceachi Data 28 martie 2010 15:10:25
Problema Factorial Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<fstream.h>
#define endl '\n'
ifstream fin("fact.in");
ofstream fout("fact.out");
int main() {

long long x,p,gst,z,y,c,mij;
fin>>p;
if(p==0) { mij=1;gst=1; goto finish ; }

x=1;
while(x<=p)   x=x*5;y=x;x=x*5;
gst=0;
while(y<=x) {
	mij=(y+x)/2;
	mij=mij/5*5;
	c=mij;
	z=0;
	while(c) {
		c=c/5;
		z+=c;
		}
	if(z==p) { gst=1;break; }
	else if(z<p)  y=mij;
		 else x=mij;
		 }
finish:
if(gst)  fout<<mij<<endl;
else if(gst==0) fout<<"-1"<<endl;
return 0;
}