Cod sursa(job #1327398)

Utilizator CraiuAndrei Craiu Craiu Data 26 ianuarie 2015 18:08:08
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<fstream>

using namespace std;

int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int n;
    long long a=1,b=100000000,m,x;
    fin>>n;
    while(a<=b)
    {
        m=(a+b)/2;
        x=m;
        int c=0;
        while(m!=0)
        {
            c+=m/5;
            m/=5;
        }
        if(c==n)
        {
            if(x-x%5==0)
                fout<<"1";
            else fout<<x-x%5;
            b=-1;
        }
        else a=(a+b)/2+1;
    }
    if(b!=-1)
        fout<<"-1";
    fin.close();
    fout.close();
    return 0;
}