Hdu-6470 Count(简单构造矩阵)

公式: f ( n ) = f ( n − 1 ) + 2 ∗ f ( n − 1 ) + n 3 f(n)=f(n-1)+2*f(n-1)+n^3 f(n)=f(n1)+2f(n1)+n3

#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int Max_n=6;
const int mod=123456789;

int n=6;
struct Mat{
	ll m[Max_n][Max_n];
	Mat(){memset(m,0,sizeof(m));}
	Mat(ll s[6][6]){
		for(int i=0;i>=1;
		base=base*base;
	}
	return ans;
}


int main()
{
	ll s[6][6]={
		{1,2,1,3,3,1},
		{1,0,0,0,0,0},
		{0,0,1,3,3,1},
		{0,0,0,1,2,1},
		{0,0,0,0,1,1},
		{0,0,0,0,0,1}
	};
	int t;ll k;
	cin>>t;
	while(t--){
		scanf("%lld",&k);
		Mat base(s);
		Mat mat=quickMod(base,k-2);
		ll a[6]={2,1,8,4,2,1};
		ll sum=0;
		for(int i=0;i<6;i++){
			sum=(sum+mat.m[0][i]*a[i])%mod;
		}
		cout<

你可能感兴趣的:(Acm--模板题)