mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 22:28:48 +00:00
#1789. 【2017.3 长乐省选集训 Day15 T1】斐波那契
https://sjzezoj.com/submission/65549
This commit is contained in:
parent
a97d1c11ac
commit
8006c15b15
88
S2OJ/1789/1789.cpp
Normal file
88
S2OJ/1789/1789.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 1e5 + 5;
|
||||||
|
const int mod = 1e9 + 7;
|
||||||
|
|
||||||
|
class Matrix {
|
||||||
|
private:
|
||||||
|
long long data[10][10];
|
||||||
|
|
||||||
|
public:
|
||||||
|
Matrix() {
|
||||||
|
memset(data, 0x00, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
long long* operator[](long long i) {
|
||||||
|
return data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix operator*(Matrix b) const {
|
||||||
|
Matrix c;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
for (int k = 0; k < 3; k++) {
|
||||||
|
c[i][j] = (c[i][j] + data[i][k] * b[k][j] % mod) % mod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix operator-(Matrix b) const {
|
||||||
|
Matrix c;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
c[i][j] = (data[i][j] - b[i][j] + mod) % mod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
} base, ans;
|
||||||
|
|
||||||
|
Matrix binpow(Matrix a, long long k) {
|
||||||
|
Matrix res;
|
||||||
|
|
||||||
|
res[1][1] = 1;
|
||||||
|
res[2][2] = 1;
|
||||||
|
|
||||||
|
while (k) {
|
||||||
|
if (k & 1) res = res * a;
|
||||||
|
a = a * a;
|
||||||
|
k >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int t, n, k;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
cin >> n >> k;
|
||||||
|
|
||||||
|
Matrix tmp;
|
||||||
|
|
||||||
|
tmp[1][1] = 0, tmp[1][2] = 1;
|
||||||
|
tmp[2][1] = 1, tmp[2][2] = 1;
|
||||||
|
|
||||||
|
cout << binpow(binpow(tmp, n + 1) - tmp, k)[2][2] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
S2OJ/1789/data/fib1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/fib9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/fib9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1789/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1789/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user