Mai intai trebuie sa te autentifici.

Cod sursa(job #314705)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 12 mai 2009 17:49:46
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<fstream.h>
#include<values.h>

long long x,mij,k,p,t;

int nrz(long x)
    {
    long y=0;
    while (x)
          {
          y+=x/5;
          x/=5;
          }
    return y;
    }
int caut_bin()
    {
    long long st,dr,mij;
    st=1;
    dr=100000000;
    mij=(st+dr)/2;
    while (st<=dr)
          {
          k=nrz(mij);
          if (k==p) return mij;
          else if(x>p)
               {
               dr=mij-1;
               mij=(st+dr)/2;
               }
          else {
               st=mij+1;
               mij=(st+dr)/2;
               }
          }
    return -1;
    }

int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
t=caut_bin();
g<<t<<'\n';
return 0;
}