Cod sursa(job #447235)

Utilizator bumble.beeBuhai Diana bumble.bee Data 28 aprilie 2010 08:38:27
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
# include <fstream.h>
long c[12];
int main ()
{
	ifstream f("fact.in");
	ofstream g("fact.out");
	long k,i;
	f>>k;
	while (k>155)
	{	i=1;
		c[i]+=125;
		c[++i]+=25;
		c[++i]+=5;
		k-=125;
		while (c[i]%5==0)
		{	i++;c[i]++;k--;}
	}
	while (k>0)
	{	i=1;
		c[i]++;
		k--;
		while (c[i]%5==0) {i++;c[i]++;k--;}
	}
	if (k==0 && c[1]>0) g<<c[1]*5<<'\n';
	else if (c[1]==0) g<<'0'<<'\n';
	else g<<"-1"<<'\n';
	return 0;
}