Cod sursa(job #2325541)

Utilizator teodorgTeodor G teodorg Data 22 ianuarie 2019 18:47:35
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p,lo,hi,mi;
int nr5(int);
int main()
{
    f>>p;
    if(!p){g<<1;return 0;}
    hi=5*p;
    while(hi-lo>1)
    {
        mi=(lo+hi)/2;
        if(nr5(mi)>=p)
            hi=mi;
        else
            lo=mi;
    }
    if(nr5(hi)!=p)
        g<<"-1";
    else
        g<<hi;
    return 0;
}
int nr5(int x)
{
    int ret=0;
    while(x/5)
    {
        ret+=x/5;
        x/=5;
    }
    return ret;

}