Cod sursa(job #40363)

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