Cod sursa(job #2250759)

Utilizator danielsociuSociu Daniel danielsociu Data 30 septembrie 2018 17:32:39
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
std::ifstream cin("fact.in");
std::ofstream cout("fact.out");

int countZero(long long x){
    int sol=0, i=5;
    while(x/i>0)
        sol+=x/i, i*=5;
    return sol;
}

int main()
{
    long long int p,st,dr;
    cin>>p;
    if(p==0){
        cout<<1;
        return 0;
    }
    st=5,dr=5*p;
    while(st<dr){
        long long int m=(st+dr)/2;
        if(countZero(m)<p)
            st=m+1;
        else
            dr=m;
    }
    if(countZero(st)==p)
        cout<<st;
    else
        cout<<-1;
}