Cod sursa(job #2078971)

Utilizator xkz01X.K.Z. xkz01 Data 30 noiembrie 2017 12:55:22
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<cstdio>
#include<climits>
using namespace std;
int n;
int cauta_bin(){
    int st=1, dr=INT_MAX, mij, x, nrZero;
    if (n==0) return 1;
    while (st<=dr) {
        mij=st+(dr-st)/2;
        x=mij; nrZero=0;
        while (x>0) {nrZero+=x/5; x/=5;}
        if (nrZero==n) return (mij-mij%5);
        if (nrZero<n) st=mij+1;
            else dr=mij-1;
    }
    return -1;
}
int main(){
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%d", &n);
    printf("%d\n", cauta_bin());
    return 0;
}