Cod sursa(job #1284715)

Utilizator tudorcomanTudor Coman tudorcoman Data 6 decembrie 2014 19:23:23
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <cstdio>
using namespace std;

int p;

int NR0(int n)
{
    int x = 0;
    for(; n; x += n / 5, n /= 5);
    return x;
}

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);

    scanf("%d", &p);

    int st = 1, dr = 5 * p, mid, rez = 1;
    while(st <= dr)
    {
        mid = (st + dr) / 2;
        if(NR0(mid) >= p)
            rez = mid, dr = mid - 1;
        else
            st = mid + 1;
    }

    if(NR0(rez) == p)
        printf("%d\n", rez);
    else printf("-1\n");
}