Cod sursa(job #1801970)

Utilizator edynator34Nechitoaia George-Edward edynator34 Data 9 noiembrie 2016 19:00:30
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;
int st,dr,x,m;
FILE *f,*g;
void fisier()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
}
 
int zero (int x)
{
    int nr=0,i=5;
    while (i<=x){
        nr+=x/i;
        i*=5;
    }
    return nr;
}
 
int main()
{
    fisier();
    scanf("%d",&x);
    if(x==0) {printf("1");
    return 0;
}
    st=1;dr=5*x;
bool ok=0;
    while(st<=dr)
    {
        m=st+(dr-st)/2;
        if(zero(m)==x){
            ok=1;
            dr=m-1;
        }
        else
        if(zero(m)>x)dr=m-1;
        else st=m+1;
    }
    if(ok)printf("%d",st);
    else
    printf("-1");
    return 0;
}