Cod sursa(job #21453)

Utilizator krisCristina kris Data 23 februarie 2007 16:57:17
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<fstream.h>
#include<math.h>

unsigned long fo(unsigned long k) {
	if(k/5==0) return 0;
	 else return k/5+fo(k/5);
}
main() {
	unsigned long n,m,p,c;
	ifstream f("fact.in");
	ofstream g("fact.out");
	f>>p;


	n=0;m=10000000;

	if(p==1) g<<0;
	else
	if(p==5) g<<-1;
	else
	  {		
		do{
			c=(n+m)/2;
	        if(fo(c)<p) n=c+1;
		     else
	         if(fo(c)>p) m=c-1;
		}while(fo(c)!=p);   
	     
		
     g<<c;
	}
return 0;
}