Cod sursa(job #281205)

Utilizator EstiarteManuel Esanu Estiarte Data 13 martie 2009 21:44:37
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<stdio.h>
FILE *in=fopen("fact.in","rt");
FILE *out=fopen("fact.out","wt");
long int p;
long int zero(long int n,long int f)
{
 long int total,nr;
 if(n==5) return 1;
 total=0;
 nr=f;
 while(nr<n)
 {
	total=total+n/nr;
	nr=nr*f;
 }
 return total;
}
long int solutie(long int a,long int b)
{
 long int mijloc,num;
 if(a>b) return -1;
 else
 {
 mijloc=(a+b)/2;
 num=zero(mijloc,5);
 if(num==p) return mijloc;
 else
	 if(num<p)

		return solutie(mijloc+1,b);
	 else
		return solutie(a,mijloc-1);
 }
}
int main()
{
 long int n,k;
 fscanf(in,"%ld",&p);
 if(p==0) fprintf(out,"1");
 else if(p==1) fprintf(out,"5");
 else if(p==2) fprintf(out,"10");
 else if(p==3) fprintf(out,"15");
	else if(p==4) fprintf(out,"20");
	 else if(p==5) fprintf(out,"-1");
		else if(p==6) fprintf(out,"25");
		else if(p==11) fprintf(out,"-1");



 else
 {
	k=solutie(25,500000000);
	k=k-k%5;
	fprintf(out,"%ld",k+1);

 }
 return 0;
}