Cod sursa(job #1696069)

Utilizator manciu_ionIon Manciu manciu_ion Data 28 aprilie 2016 13:08:30
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <cstdio>

using namespace std;

int getCountOfZeros(int );
int binarySearch(int );

int main()
{
    FILE *F;
    F = freopen("fact.in", "rt", stdin);
    F = freopen("fact.out", "wt", stdout);

    int err, n, ans;
    err = scanf("%d", &n);
    ans = binarySearch(n);
    printf("%d\n", (getCountOfZeros(ans) == n) ? ans : -1);
    return 0;
}

 int getCountOfZeros(int x) {
        int count = 0;
        while (x > 0) {
            x /= 5;
            count += x;
        }
        return count;
}


int binarySearch(int x) {
        int i = -1;
        for (int step = 1 << 30; step > 0; step >>= 1)
           if ( getCountOfZeros(i + step) < x) {
               i += step;
           }
        return ( i + 1 );
}