Mai intai trebuie sa te autentifici.
Cod sursa(job #38686)
| Utilizator | Data | 25 martie 2007 23:13:35 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <stdio.h>
#include <math.h>
FILE *f;
long a[16],i;double l,x=1,y=500000000,s,n;
int main()
{f=fopen("fact.in","r");fscanf(f,"%lf",&n);fclose(f);
a[1]=5;a[2]=25;a[3]=125;a[4]=625;a[5]=3125;a[6]=15625;a[7]=78125;
a[8]=390625;a[9]=1953125;a[10]=9765625;a[11]=48828125;a[12]=244140625;
while(s!=n&&x!=y)
{l=floor((x+y)/2);s=0;
for(i=1;i<=12;i++)s+=floorl(l/a[i]);
if(s<n)x=l+1;else if(s>n)y=l-1;
}
f=fopen("fact.out","w");
if(s==n)while(fmodl(l,5))l--;
if(n==0)l=1;if(s==n)fprintf(f,"%.0lf",l);else fprintf(f,"-1");
fclose(f);
return 0;
}