Cod sursa(job #1749715)

Utilizator Mircea_DonciuDonciu Mircea Mircea_Donciu Data 28 august 2016 16:59:09
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>

using namespace std;
long long p,st,dr,m;
int functie(int x)
{
    int s;
    s=0;
    while(x)
    {
        s+=x;
        x/=5;
    }
    return s;
}
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    if(p)
    {
        st=4*p/5;
        dr=p+1;
        while(st+1<dr)
        {
            m=(st+dr)/2;
            if(functie(m)>=p) dr=m;
            else st=m;
        }
        if(functie(st)==p) g<<5*st<<'\n';
        else if(functie(dr)==p) g<<5*dr<<'\n';
        else g<<"-1"<<'\n';
    }
    f.close(); g.close();
    return 0;
}