Cod sursa(job #1429042)

Utilizator dumbraveanbDumbravean Bogdan dumbraveanb Data 5 mai 2015 16:16:40
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;

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

long long nmax = 1 << 20, n, k = 1, x;

long cinci(long n)
{
    long x = 0;
    for(long i = 5; i <= n; i *= 5)
        x += n / i;
    return x;
}

int main()
{
    fin >> n;

    k = x = nmax;

    for(; k; k /= 2)
        if(x - k >= 0 && cinci(x - k) >= n) x -= k;

    if(x == nmax || cinci(x) != n) fout << -1;
    else if(x > 0) fout << x;
    else fout << 1;
    return 0;
}