Mai intai trebuie sa te autentifici.
Cod sursa(job #535802)
| Utilizator | Data | 17 februarie 2011 19:37:47 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | c | Status | done |
| Runda | Arhiva de probleme | Marime | 0.76 kb |
#include<stdio.h>
#include<math.h>
long int p;
long int cauta(long int a,long int b)
{
long int c=(a+b)/2,s=0;
int i=1,y=5;
while(y<=c)
{
s+=c/y;
y*=5;
}
if(s==p) {if(c%5) return c-c%5; else return c;}
else {if(a==b) return -1;
if(s<p) return cauta(c+1,b);
if(s>p) return cauta(a,c-1);
}
}
int main()
{
long int b;
FILE *f=fopen("fact.in","rt");
fscanf(f,"%ld",&p);
b=5*p;
FILE *h=fopen("fact.out","wt");
if(p==0) fprintf(h,"1");
else {long int x=cauta(0,b);
fprintf(h,"%ld",x);
}
return 0;
}
