[ create a new paste ] login | about

Link: http://codepad.org/SAca462l    [ raw code | output | fork ]

didyxdi - C++, pasted on Sep 3:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<ctime>
using namespace std;
typedef long long ll;

struct node
{
	ll a[5][5];
};

int T;
const ll INF=10007;
int n;
node ans,it;

void init()
{
	it.a[0][0]=2;it.a[0][1]=1;it.a[0][2]=0;
	it.a[1][0]=2;it.a[1][1]=2;it.a[1][2]=2;
	it.a[2][0]=0;it.a[2][1]=1;it.a[2][2]=2;
}

node multiple(node x,node y)
{
	node t;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			t.a[i][j]=(x.a[i][0]*y.a[0][j])%INF+(x.a[i][1]*y.a[1][j])%INF+(x.a[i][2]*y.a[2][j])%INF;
			t.a[i][j]=t.a[i][j]%INF;
		}
	}
	return t;
}

node pow(node x,int p)
{
	if(p==1) return x;
	node tmp=multiple(x,x);
	if(p & 1) return multiple(pow(tmp,p/2),x);
	else return pow(tmp,p/2);
} 

int main()
{
	init();
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		ans=pow(it,n);
		printf("%I64d\n",ans.a[0][0]);
	}
	return 0;
}


Output:
1
2
Line 14: error: ISO C++ does not support 'long long'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: