Cod sursa(job #1060636)

Utilizator bratiefanutBratie Fanut bratiefanut Data 18 decembrie 2013 11:06:02
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

long long st,dr,mij,p,sol;

long long verif(int x)
{
    long long nr=0;
    while(x>=5)
    {
        nr=nr+x/5;
        x=x/5;
    }
    return nr;
}
int main()
{
    f>>p;
    if(p==0)
    g<<1;
    else
    {
        st=1;
        dr=500000000;
        sol=-1;
        while(st<=dr)
        {
            mij=(st+dr)/2;
            if(verif(mij)>p)dr=mij-1;
            else if(verif(mij)<p)st=mij+1;
            else {sol=mij;dr=mij-1;}
        }
        g<<sol;
}
return 0;
}