Cod sursa(job #2064038)

Utilizator cyg_ionutStan Ionut Gabriel cyg_ionut Data 11 noiembrie 2017 18:43:38
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int n;

int zero(int x) {
    int ans = 0;
    while (x / 5 > 0) {
        ans = ans + x / 5;
        x = x / 5; }
    return ans; }

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

    scanf("%d", &n);

    for (i64 bit = 1LL << 30; bit > 0; bit = bit / 2)
        if (zero(bit + ans) < n)
            ans = ans + bit;
    ans+= 1;

    if (zero(ans) != n)
        printf("-1\n");
    else
        printf("%d\n", ans);

    return 0; }