Cod sursa(job #2077429)

Utilizator madalin98Gherghe Madalin madalin98 Data 28 noiembrie 2017 01:18:55
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int dr=1000000000;
int zero(int x)
{
    int nr=0,n=5;
    while(x/n!=0){
        nr+=x/n;
        n*=5;
    }
    return nr;
}
int main()
{
    int p,st,m;
    f>>p;
    st=1;
   m=(st+dr)/2;
    while(zero(m)!=p&&st<=dr)
    {
        m=(st+dr)/2;
        if(zero(m)>p)dr=m-1;
          else st=m+1;
    }
    while(zero(m)==zero(m-1))
        m--;
    if(zero(m)==p)g<<m;
      else g<<-1;
    return 0;
}