Cod sursa(job #2234763)

Utilizator anne_marieMessner Anne anne_marie Data 26 august 2018 02:16:11
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");


long long verif(long long x)
{
    long long c = 0, p, i;
    for( p = 5 ; p <= x ; p *= 5)
        c += x / p;
    return c;
}

int main()
{
    int t, p, i = 1;
    fin >> p;
    if (p == 0)
    {
        fout << 1 << '\n';
        return 0;
    }
    int st = 1, dr = p * 5, mij, x;
    while (st <= dr)
    {
        mij = (st + dr) / 2;
        x = verif(mij);
        if(x == p)
            {
                while(mij % 5 != 0)
            mij --;
        fout << mij << '\n';
        return 0;
            }
            if(x > p)
                dr = mij - 1;
            else
                st = mij + 1;
    }
    fout << -1 <<'\n';
    return 0;
}