Cod sursa(job #1249554)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 27 octombrie 2014 09:46:37
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;

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

inline int exp (const int &N)
{
    int P = 5;
    int e = 0;

    while (N >= P){
        e += (N / P);
        P *= 5;
    }

    return e;
}

int main()
{
    int P, i = 0, step, X;

    in >> P;
    X = 5 * P;

    for (step = 1; step < X; step <<= 1);
    for ( ;step; step >>= 1)
        if (i + step <= X && exp (i + step) < P)
            i += step;

    out << i + 1;

    return 0;
}