Cod sursa(job #1045907)

Utilizator cristy202020Totolin Cristian cristy202020 Data 2 decembrie 2013 12:09:21
Problema Factorial Scor 25
Compilator c Status done
Runda Arhiva de probleme Marime 0.53 kb
//http://www.infoarena.ro/problema/fact

#include<stdio.h>
int min (int x,int y)
{
	if (x<=y)
		return x;
	else
		return y;
}
int main()
{
	FILE *f=fopen ("fact.in","r");
	FILE *g=fopen ("fact.out","w");
	
	long p;
	long cinci=0,doi=0,k,x;

	fscanf (f,"%d",&p);
	k=1;
	while (min(cinci,doi)<p)
	{
		k++;
		x=k;
		while (x%2==0)
		{
			x=x/2;
			doi++;
		}
		while (x%5==0)
		{
			x=x/5;
			cinci++;
		}
	}
	if (min(doi,cinci)==p)
	fprintf (g,"%d",k);
	else
		fprintf (g,"-1");
	return 0;
}