Cod sursa(job #73558)

Utilizator M@2Te4iMatei Misarca M@2Te4i Data 19 iulie 2007 16:29:07
Problema Sarpe Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include<stdio.h>
#include<string.h>
#define VAL 100000
long long n,w;
int q[VAL],e[VAL];

void citire()
{
	freopen("sarpe.in","r",stdin);
	scanf("%lld", &n);
	fclose(stdin);
}

void printare()
{
	for (int i=1; i<=q[0]; i++)
		printf("%d",q[i]);
}

void transf(long long q, int a[VAL])
{
	while (q>0)
	{
		a[++a[0]]=q%10;	
		q/=10;
	}
}

void mult(int A[VAL], int B[VAL])
{  
	int i, j, t, C[VAL];
    memset(C, 0, sizeof(C));  
    for (i = 1; i <= A[0]; i++)  
    {  
		for (t=0, j=1; j <= B[0] || t; j++, t/=10)  
			C[i+j-1]=(t+=C[i+j-1]+A[i]*B[j])%10;  
		if (i + j - 2 > C[0]) C[0] = i + j - 2;  
	}  
    memcpy(A, C, sizeof(C));  
} 

void numere_mari()
{
	transf(4*n,q);
	//n*=4;
	//q=2*n-1;
	transf(2*(n-1),e);
	transf(n-2,e);
	mult(q,e);
	transf(4*n,e);
	mult(q,e);
		
}

int main()
{
	citire();
	freopen("sarpe.out","w",stdout);
	if (n>1)
	{
		//w=4*n+2*(n-1)*(n-2);
		numere_mari();
		printare();
	}
	else 
	{
		w=2;
		printf("%lld",w);
	}
	fclose(stdout);
	printare();
	return 0;
}