Cod sursa(job #1027559)

Utilizator morlockRadu Tatomir morlock Data 12 noiembrie 2013 21:02:24
Problema Factorial Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

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

long long P, step, N, Z, temp, nr, i, nr1;

long fact(long long N)
{ long long Z = 0, temp = 5;

    while ( temp <= N )
    {
        Z += N / temp;
        temp *= 5;
    }

    return Z;
}

int main()
{
    in >> P;

    if ( !P ) out << 1;

    else
    {
        step = 1ll<<30;
        for ( i = 1; step >= 5; step >>= 1 )
        {
           // cout << step << " " << fact(step) << '\n';
            if ( fact(i+step) <= P )
            {
               i += step;
            }
        }

    }

    out << i - (i % 5);
return 0;
}