比赛 |
欢乐五一练练练 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数学序列 |
最终得分 |
100 |
用户昵称 |
TARDIS |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2017-05-01 08:05:53 |
显示代码纯文本
#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;
}
int main(){;}
int xlm=Main();