Cod sursa(job #156115)

Utilizator jeanFMI - Petcu Ion Cristian jean Data 12 martie 2008 12:52:51
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include<fstream.h>
#include<math.h>
long s=1,d=2000000,m,k,c,z=0;
int n,p;
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>n;
m=(s+d)/2;
while (z!=n&&s<d)
 {z=0; k=5;p=1;
  while(k<=m)
   {
   c=m/k; z+=c;
   p++;
   k=pow(5,p);
   }
   if(z<n)   {s=m+1; m=(s+d)/2;}
    else if(z>n) {d=m-1; m=(s+d)/2;}
  }
if(z==n) g<<m-(m%5);
 else g<<"-1";
f.close();
g.close();
return 0;
}