比赛 |
欢乐五一练练练 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数学序列 |
最终得分 |
100 |
用户昵称 |
sxysxy |
运行时间 |
0.004 s |
代码语言 |
C++ |
内存使用 |
0.29 MiB |
提交时间 |
2017-04-26 21:04:08 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
struct matrix{
int a[3][3];
};
void matrix_puts(matrix &x, int m, int n){
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
printf("%d ", x.a[i][j]);
}
putchar('\n');
}
}
void matrix_mul(matrix A, matrix B, matrix &C, int m, int n, int p){
for(int i = 1; i <= m; i++)
for(int j = 1; j <= p; j++){
C.a[i][j] = 0;
for(int k = 1; k <= n; k++)
C.a[i][j] = (C.a[i][j]+A.a[i][k]*B.a[k][j])%7;
}
}
matrix matrix_pow(matrix a, long long x){
matrix ans;
ans.a[1][1] = ans.a[2][2] = 1;
ans.a[1][2] = ans.a[2][1] = 0;
matrix tmp;
for(; x; x >>= 1){
if(x&1){
matrix_mul(ans, a, tmp, 2, 2, 2);
ans = tmp;
}
matrix_mul(a, a, tmp, 2, 2, 2);
a = tmp;
}
return ans;
}
int main(){
freopen("number1.in", "r", stdin);
freopen("number1.out", "w", stdout);
int a, b;
long long n;
while(~scanf("%d %d %lld", &a, &b, &n)){
if(n < 2){
puts("1");
continue;
}
matrix x;
x.a[1][1] = a; x.a[2][1] = b;
x.a[1][2] = 1; x.a[2][2] = 0;
x = matrix_pow(x, n-2);
matrix s;
s.a[1][1] = s.a[1][2] = 1;
matrix r;
matrix_mul(s, x, r, 1, 2, 2);
printf("%d\n", r.a[1][1]);
}
return 0;
}