Cod sursa(job #930349)

Utilizator BlueStrutAndrei Prahoveanu BlueStrut Data 27 martie 2013 16:31:36
Problema Factorial Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<cstdio>
using namespace std;
long long i, n, st, dr, mij, x;
long long corect(long long x){
    long long rez; rez=0;
    while (x>=5) {rez+=x/5; x=x/5;}
    if (rez>=n) return 0; else return 1;
}
long long corectfix(long long x){
    long long rez; rez=0;
    while (x>=5) {rez+=x/5; x=x/5;}
    if (rez==n) return true; else return false;
}
int main(){
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%lld", &n);
    st=1; dr=10*10*10*10*10*10*10*10*10*10*10*10*10*10;
    while (dr-st>=2) {
        mij=(st+dr)/2;
        x=corect(mij);
        if (x==0) dr=mij; else st=mij;
    }
    if (corectfix(st)==true) printf("%lld\n", st); else printf("%lld\n", dr);
    return 0;
}