Cod sursa(job #1197524)

Utilizator Narcys01Ciovnicu Narcis Narcys01 Data 12 iunie 2014 13:03:33
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int p, st, dr, nr, i, n;
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
    scanf("%d", &p);
    st = n = 0;
    dr = 100000000;
    while (st <= dr)
    {
        n = (st + dr) / 2;
        nr = 0;
        i = 5;
        while (i <= n)
        {
            nr += n / i;
            i *= 5;
        }
        if (p <= nr)
            dr = n - 1;
        else
            st = n + 1;
    }
    if (st == 0)
        printf("1");
    else
        printf("%d", st);
    return 0;
}