Cod sursa(job #1839639)

Utilizator IsacLucianIsac Lucian IsacLucian Data 3 ianuarie 2017 11:41:19
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int Verificare(int x)
{
    int sol=0,k=5;
    while(k<=x)
    {
        sol+=x/k;
        k*=5;
    }
    return sol;
}
inline int CautBin()
{
    int st=1,dr=(1<<30),mij,sol=0;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(Verificare(mij)==p)
        {
            sol=mij;
            dr=mij-1;
        }
        else if(Verificare(mij)>p)
            dr=mij-1;
        else st=mij+1;
    }
    return sol;
}
int main()
{
    int x;
    fin>>p;
    x=CautBin();
    if(!x)
        fout<<"-1\n";
    else fout<<x<<"\n";
    fin.close();
    fout.close();
    return 0;
}