Cod sursa(job #2069517)

Utilizator AnnaLipianuLipianu Ana AnnaLipianu Data 18 noiembrie 2017 15:26:51
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int n,s,p,x,dr,st,m,ok;
cin>>x;
if(x==0)cout<<1;
else{
st=1;
dr=5*x;
ok=0;
while(st<=dr&&ok==0)
{
    n=(st+dr)/2;
    p=5;
    s=0;
    while(n/p>0)
    {
        s=s+n/p;
        p*=5;
    }
    if(s==x){
            cout<<n/5*5;
           ok=1;
            }
   if(s>x)dr=n-1;
        else {st=n+1;
             }
}
if(s!=x)cout<<-1;
}
  return 0;
}