Cod sursa(job #1454311)

Utilizator piroComisia piro Data 26 iunie 2015 01:15:37
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>

int check(int n) {
    int sum = 0, power = 5;
    while (power <= n) {
        sum += n / power;
        power *= 5;
    }
    return sum;
}

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

    int p;
    scanf("%d", &p);
    if (p == 0) {
        printf("1");
        return 0;
    }
    int st = 0, dr = 5 * p, res;
    while (st <= dr) {
        int med = ((long long)st + dr) / 2;
        if (check(med) >= p) {
            res = med;
            dr = med - 1;
        } else
            st = med + 1;
    }
    printf("%d", res);
    return 0;
}