Cod sursa(job #1283181)

Utilizator RaduVisanRadu Visan RaduVisan Data 5 decembrie 2014 11:14:46
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <cstdio>
using namespace std;

int P;

int Count0(int N)
{
    int Ans = 0;
    for(; N; Ans += N / 5, N /= 5);
    return Ans;
}

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

    scanf("%i", &P);

    int Left = 1, Right = 5 * P, Mid, Ans = 1;
    while(Left <= Right)
    {
        Mid = (Left + Right) / 2;
        if(Count0(Mid) >= P) Ans = Mid, Right = Mid - 1;
        else Left = Mid + 1;
    }

    if(Count0(Ans) == P) printf("%i\n", Ans);
    else printf("-1\n");
}