Cod sursa(job #1269179)

Utilizator nicomuresanmuresan nicoleta nicomuresan Data 21 noiembrie 2014 22:55:13
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <cstdio>
 
using namespace std;
 
int f0(int n) {
    int ret = 0, p = 5;
    while (n >= p) {
        ret += n / p;
        p *= 5;
    }
 
    return ret;
}
 
int main() {
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
 
    int N; scanf("%d", &N);
 
    int poz = 0, pas = 1<<29;
    while (pas >>= 1) {
        if (f0(pas + poz) <= N) {
            poz += pas;
        }
    }
    poz -= 4;
 
    if (f0(poz) == N) {
        if (poz == 0) poz = 1;
        printf("%d", poz);
    } else {
        printf("-1");
    }
 
    return 0;
}