Cod sursa(job #930336)

Utilizator BlueStrutAndrei Prahoveanu BlueStrut Data 27 martie 2013 16:27:48
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<cstdio>
using namespace std;
int i, n, st, dr, mij, x;
int corect(int x){
    int rez; rez=0;
    while (x>=5) {rez+=x/5; x=x/5;}
    if (rez>=n) return 0; else return 1;
}
int corectfix(int x){
    int 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("%d", &n);
    st=1; dr=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("%d\n", st); else printf("%d\n", dr);
    return 0;
}