Cod sursa(job #344181)

Utilizator mathboyDragos-Alin Rotaru mathboy Data 28 august 2009 21:34:19
Problema Patrate2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <cstdio>
#include <string>
#define DIM 2<<13
int a[DIM],n,c[DIM],b[DIM];
long long m;
using namespace std;
void mul(int A[], int B)
{
      int i, t = 0;
      for (i = 1; i <= A[0] || t; i++, t /= 100)
              A[i] = (t += A[i] * B) % 100;
      A[0] = i - 1;
}
void mula(int A[], int B[])
{
      int i, j, t, C[10000];
      memset(C, 0, sizeof(C));
      for (i = 1; i <= A[0]; i++)
      {
              for (t=0, j=1; j <= B[0] || t; j++, t/=100)
                      C[i+j-1]=(t+=C[i+j-1]+A[i]*B[j])%100;
              if (i + j - 2 > C[0]) C[0] = i + j - 2;
      }
      memcpy(A, C, sizeof(C));
}

void solve()
{   
    int i;
    a[0]=1;a[1]=1;
    for (i=2; i<=n; ++i) mul(a,i);
    m=n*n;
    b[0]=1;b[1]=1;
    c[0]=1;c[1]=2;
    while (m)
	{
		if (m%2)
			mula(b,c);
		mula(c,c);
		m/=2;
	}

    mula(a,b);
    printf("%d",a[a[0]]);
    for (i=a[0]-1; i>=1; --i) printf("%.2d",a[i]);
}    
int main()
{   
    freopen ("patrate2.in","r",stdin);
    freopen ("patrate2.out","w",stdout);
    scanf("%d",&n);
    solve();
    return 0;
}