Cod sursa(job #40423)

Utilizator znakeuJurba Andrei znakeu Data 27 martie 2007 13:55:01
Problema Factorial Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <stdio.h>
int main()
{
	int k,k1,k2,kt,f=0;
	
	FILE *in=fopen("fact.in","r");
	FILE *out=fopen("fact.out","w");
	fscanf(in,"%d",&k);
	fclose(in);
	
	if (k)
	{
		k1=k;
		while (f==0)
		{
			kt=k1;
			k2=0;
			while (kt)
			{
				k2+=kt/5;
				kt/=5;				
			}
			if (k1+k2==k)
				f=1;
			if (k1+k2<k)
				f=-1;
			if (!f)
				k1--;
		}
		
		if (f==1)
			fprintf(out,"%d\n",k1*5);
		else
			fprintf(out,"-1\n");
	}
	else
		fprintf(out,"1\n");
	fclose(out);
	
	return 0;
}