Cod sursa(job #2077840)

Utilizator gumitza68Marsky7 gumitza68 Data 28 noiembrie 2017 17:52:23
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<iostream>
#include<fstream>
using namespace std;
int n,p;
long int dr=100000000000,m,st;
ifstream f("fact.in");
ofstream g("fact.out");
int zero(int x)
{
    int nr=0,n=5;
    while(x/n!=0)
    {
        nr+=x/n;
        n*=5;
    }
    return nr;
}
int main()
{
    f>>p;
    if(p==0) g<<1;
    else
    {
        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;
    }
    f.close();
    return 0;
}