Cod sursa(job #30317)

Utilizator razvi9Jurca Razvan razvi9 Data 13 martie 2007 19:03:28
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include<stdio.h>
long nr,p,nrz[31]={0,1,2,3,4,6,7,8,9,10,12,13,14,15,16,18,19,20,21,22,24,25,26,27,28,31,32,33,34,35,37};
long nz(long p)
{long nr=0;
 while(p%5==0) {nr++;  p=p/5;}
 return nr;}
long nrzero(long n)
{long nr=0;
 if(n/5<=30) return nrz[n/5];
 nr=nrz[30];
 for(int i=31*5;i<=n;i=i+5)
  nr=nr+1+nz(i/5);
 return nr;}
long div(long inc,long sf)
{long m=(inc+sf)/2,nz;
 nz=nrzero(m);
 if(nz==p) return m;
 if(nz<p) return div(m,sf);
 return div(inc,m);
}
int main()
{freopen("fact.in","r",stdin);
 scanf("%ld",&p);
 fclose(stdin);
 if(p==0) nr=1;
 else nr=div(1,5*p);
 while(nr!=1&&nr%5) nr--;
 freopen("fact.out","w",stdout);
 printf("%ld",nr);
 fclose(stdout);
 return 0;}