Cod sursa(job #2069475)
Utilizator | Data | 18 noiembrie 2017 14:41:38 | |
---|---|---|---|
Problema | Factorial | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.41 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;
cin>>x;
st=1;
dr=5*x;
while(st<=dr)
{
n=(st+dr)/2;
p=5;
s=0;
while(n/p>0)
{
s=s+n/p;
p*=5;
}
if(s>x)dr=n-1;
else st=n+1;
}
if(x==0)cout<<1;
else if(s!=x)cout<<-1;
else
cout<<n;
return 0;
}