Cod sursa(job #1566939)

Utilizator dobricean_ionutDobricean Ioan dobricean_ionut Data 12 ianuarie 2016 20:08:55
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include  <iostream>
#include  <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int n,p;

void cit()
{ fin>>p;

}

int nr_0(int x)
{ int z=0,t=5;
if(x==0)
    return 1;
else
while(t<=x)
{ z=z+x/t;
t=t*5;

}

return z;
}

void cautare_binara()
{
    long long st=1,sd=100000,g=0,m,b=0,s=0;
    while(st<=sd && g==0)
    {
        m=(st+sd)/2;
        s=nr_0(m);
      //  cout<<s<<" ";
        if(p==s)
        { b=m;
            g=1;
        }
        else
          if(p<s)
            sd=m-1;
          else  st=m+1;
    }
    while(nr_0(b) == p)b--;
fout<<b+1;
}


int main(void)
{cit();
cautare_binara();
//cout<<nr_0(p);
return 0;
}