Cod sursa(job #2035644)

Utilizator ionut_puiuPuiu Ionut ionut_puiu Data 9 octombrie 2017 18:37:31
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,lo,mi,hi,zerouri(int);
int main()
{

    int p;
    fin>>p;
    if(p==0)
    {
        fout<<1;
        return 0;
    }
    lo=0;hi=500000000;
    while(hi-lo>1)
    {
        mi=(lo+hi)/2;
        if(zerouri(mi)<p)
            lo=mi;
        else
            hi=mi;
    }
    if(zerouri(hi)==p)
        fout<<hi;
    else
        fout<<-1;
    return 0;
}
int zerouri(int x)
{
    int sol=0;
    while(x>0)
    {
        x/=5;
        sol+=x;
    }
    return sol;
}