Cod sursa(job #1872348)
| Utilizator | Data | 8 februarie 2017 09:32:07 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <cstdio>
using namespace std;
int cautbin(int p){
int st,dr,mij,s,y,x;
st=1;dr=5*p;
while(st<=dr && s!=p){
mij=(st+dr)/2;s=0;
x=mij;y=5;
while(x!=0){
x/=5;
s+=x;
y*=5;
}
if(s==p)return mij;
if(s>p)dr=mij-1;
else st=mij+1;}
if(st>dr)return -1;
return mij;
}
int p;
int main()
{freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
if(p==0)printf("1");
else
printf("%d",cautbin(p)-cautbin(p)%5);
return 0;
}
