记录编号 |
417501 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
数列求值 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.004 s |
提交时间 |
2017-06-25 20:00:45 |
内存使用 |
0.57 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char buf[1<<18],*fs,*ft;
inline char getc(){return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin)),fs==ft)?EOF:*fs++;}
inline int in(void){
char tmp = getc();
int res = 0;
while(!isdigit(tmp)) tmp = getc();
while(isdigit(tmp))
res = (res + (res << 2) << 1) + (tmp ^ 48),
tmp = getc();
return res;
}
inline void Pow(int n);
int res[2][2], s[2][2];
int _ans[1][2] = {1, 1};
int ans[1][2];
int N, A, B;
int main(){
#ifndef LOCAL
freopen("sequenceb.in", "r", stdin);
freopen("sequenceb.out", "w", stdout);
#endif
A = in(), B = in(), N = in();
for(int i = 0; i < 2; ++i) res[i][i] = 1;
s[0][0] = 0;
s[0][1] = B % 7;
s[1][0] = 1;
s[1][1] = A % 7;
Pow(N - 1);
for(int i = 0; i < 1; ++i){
for(int j = 0; j < 2; ++j){
for(int k = 0; k < 2; ++k){
ans[i][j] = (ans[i][j] + _ans[i][k] * res[k][j]) % 7;
}
}
}
printf("%d", ans[0][0]);
return 0;
}
inline void Pow(int n){
int tmp[2][2];
while(n){
if(n & 1){
memset(tmp, 0x00, sizeof(tmp));
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
for(int k = 0; k < 2; ++k){
tmp[i][j] = (tmp[i][j] + res[i][k] * s[k][j]) % 7;
}
}
}
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
res[i][j] = tmp[i][j];
}
}
}
memset(tmp, 0x00, sizeof(tmp));
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
for(int k = 0; k < 2; ++k){
tmp[i][j] = (tmp[i][j] + s[i][k] * s[k][j]) % 7;
}
}
}
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
s[i][j] = tmp[i][j];
}
}
n >>= 1;
}
return ;
}