Cod sursa(job #446913)

Utilizator myshuSpatariu Mihai-Constantin myshu Data 26 aprilie 2010 21:10:44
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<fstream.h>
#include<math.h>
long long c[13],ok[13];
int main ()
{
	ifstream fcin("fact.in");
	ofstream fcout("fact.out");
	long long k,i,s=0,j;
		fcin>>k;
	while(k>155)
		{i=1;
		c[i]=c[i]+125;i++;c[i]=c[i]+25;i++;c[i]=c[i]+5;k=k-155;
		while(c[i]%5==0)if(k>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)fcout<<c[1]*5<<'\n';
	else if(c[1]==0)fcout<<1<<'\n';
	else fcout<<-1<<'\n';
	return 0;
}