Cod sursa(job #107199)

Utilizator hadesgamesTache Alexandru hadesgames Data 19 noiembrie 2007 15:51:22
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <stdio.h>
int main()
{
	FILE *in,*out;
	int p;
	long long x,a,nr;
	in=fopen("fact.in","r");
	out=fopen("fact.out","w");
	fscanf(in,"%d",&p);
	if (p==0)
	{
		fprintf(out,"1\n");
		fclose(in);
		fclose(out);
		return 0;
	}
	x=0;
	while (p!=0)
	{
		x+=5;
		a=x;
		nr=0;
		while (a%5==0)
		{
			a/=5;
			nr++;
		}
		p-=nr;
		if (p<0)
		{
			fprintf(out,"-1\n");
			fclose(in);
			fclose(out);
			return 0;
		}
	}
	fprintf(out,"%d\n",x);
	fclose(in);
	fclose(out);
	return 0;
}