Cod sursa(job #1287629)

Utilizator iulian_moneIulian Mone iulian_mone Data 7 decembrie 2014 21:43:25
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <cstdio>
#include <algorithm>

using namespace std;

int x, n, last;

int ok(int med){
    int x = 5, Ans = 0;
    while(x < med){
        Ans += med / x;
        x *= 5;
    }
    return Ans;
}

int cb(){
    int st = 1, dr = 1 << 30;
    while(st <= dr){
        int med = (st + dr) >> 1;
        if(ok(med) >= n){
            last = med;
            dr = med - 1;
        }
        else
            st = med + 1;
    }
    if(ok(last) == n)
        return last;
    else
        return -1;
}

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