- 文科生的悲哀
- 2018-02-12 19:05:27 @
我已經拿遞歸AC了,對拍了一下也是全對,爲什麼用矩陣乘法最後四個點就是過不了?
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct matrix{
int v[2][2];
matrix(){
memset(v, 0, sizeof v);
}
matrix operator*(matrix b){
matrix c;
for (int i = 0; i < 2; i++){
for (int j = 0; j < 2; j++){
for (int k = 0; k < 2; k++){
c.v[i][j] += v[i][k] * b.v[k][j];
c.v[i][j] %= 7654321;
}
}
}
return c;
}
}ans, x;
void pm(int tmp){
while (tmp > 0){
if (tmp & 1) ans = ans * x;
x = x * x; tmp >>= 1;
}
}
int n;
int main(){
x.v[0][0] = 1, x.v[1][0] = 1, x.v[0][1] = 1; ans.v[0][0] = 1;
cin >> n;
pm(n);
cout << ans.v[0][1] % 7654321 << endl;
return 0;
}
1 条评论
-
q234rty LV 10 @ 2018-02-13 13:24:02
c.v[i][j] += v[i][k] * b.v[k][j];
爆int
了
- 1