记录编号 280871 评测结果 AAAAAAAAAA
题目名称 数学序列 最终得分 100
用户昵称 GravatarSky_miner 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2016-07-10 19:33:31 内存使用 0.29 MiB
显示代码纯文本
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const int maxn = 1000 ;
const int mod = 7;
struct Matrix{
	int a[3][3];
	Matrix(bool type){
		a[1][1] = a[1][2] = a[2][1] = a[2][2] = 0;
		if( type ){
			a[1][1] = a[2][2] = 1;
		}
	}
	Matrix operator * (const Matrix & x) const{
		Matrix res(0);
		for (int i=1; i<=2;i++){
			for (int j=1;j<=2;j++){
				for(int k = 1; k <= 2; k++){
					res.a[i][j] = (res.a[i][j]+(a[i][k]*x.a[k][j]) ) % mod;
				}
			}
		}
		return res;
	}
};
Matrix pow_mod(Matrix x,int p){
	if( p == 1 ) return x;
	Matrix t(1);
	if( p == 0 || p == -1) return t;
	while(p){
		if( p & 1 ) t = x*t;
		x = x*x;p>>=1;
	}
	return t;
}
int main(){
	freopen("number1.in","r",stdin);
	freopen("number1.out","w",stdout);
	int n,A,B;scanf("%d %d %d",&A,&B,&n);
	Matrix sc(0),po(0);
	sc.a[1][1] = sc.a[1][2] = 1;
	po.a[1][1] = A;po.a[1][2] = 1;po.a[2][1] = B;
	sc = sc*pow_mod(po,n-2);
	printf("%d\n",(sc.a[1][1]%mod));
//	getchar();getchar();
	return 0;
}