Cod sursa(job #645291)

Utilizator warchildmdMihail Burduja warchildmd Data 8 decembrie 2011 23:26:44
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <cstdio>
#define UPPER_BOUND 400000004
using namespace std;

int P;

int countZeros(int x)
{
    int sum = 0;
    while(x >= 5)
    {
        x = x/5;
        sum+=x;
    }
    return sum;
}

int search(int l, int r)
{
    int sol = 0;
    while(l < r)
    {
        int mid = (l+r)/2;
        //printf("%d - %d\n", mid, countZeros(mid));
        if(countZeros(mid) < P)
        {
            l = mid + 1;
        }
        else
        {
            sol = mid;
            r = mid;
        }
    }
    return sol;
}

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
    scanf("%d", &P);
    printf("%d", search(1, UPPER_BOUND));
    return 0;
}