Cod sursa(job #1803521)

Utilizator mihai.alphamihai craciun mihai.alpha Data 11 noiembrie 2016 16:03:08
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#define L  31
inline long long zero(long long n)  {
    long long total = 0LL;
    while(n)  {
        total += n / 5LL;
        n /= 5LL;
    }
    return total;
}

inline long long caut2(long long x)  {
    long long r = 0LL;
    long long pos = 1LL << L;
    while(pos)  {
        if(r + pos <= 1LL << L && zero(r + pos) < x)
            r += pos;
        pos /= 2LL;
    }
    if(x == zero(r + 1LL))
    return r + 1LL;
    return -1LL;
}
FILE *fin, *fout;
int main()  {
    fin = fopen("fact.in", "r");
    fout = fopen("fact.out", "w");
    long long p;
    fscanf(fin, "%lld", &p);
    fprintf(fout, "%lld", caut2(p));
    fclose(fin);
    fclose(fout);
    return 0;
}