From 826377f68738f215d27c75aba4010e9df5bb9d11 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 18 Jul 2022 17:18:15 +0800 Subject: [PATCH] =?UTF-8?q?P1306=20=E6=96=90=E6=B3=A2=E9=82=A3=E5=A5=91?= =?UTF-8?q?=E5=85=AC=E7=BA=A6=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/80117613 --- Luogu/P1306/P1306.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Luogu/P1306/P1306.cpp diff --git a/Luogu/P1306/P1306.cpp b/Luogu/P1306/P1306.cpp new file mode 100644 index 00000000..a162c1e2 --- /dev/null +++ b/Luogu/P1306/P1306.cpp @@ -0,0 +1,79 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 10; +const int mod = 1e8; + +class Matrix { + private: + long long data[N][N]; + + public: + Matrix() { + memset(data, 0x00, sizeof(data)); + } + + long long* operator[](int i) { + return data[i]; + } + + Matrix operator*(Matrix b) const { + Matrix c; + + int n = 2; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int k = 1; k <= n; k++) { + c[i][j] = (c[i][j] + data[i][k] * b[k][j] % mod) % mod; + } + } + } + + return c; + } +} base, ans; + +Matrix binpow(Matrix a, int k) { + Matrix res; + res[1][1] = 1; + res[1][2] = 1; + + while (k) { + if (k & 1) res = res * a; + a = a * a; + k >>= 1; + } + + return res; +} + +long long fib(int n) { + if (n <= 2) { + return !!n; + } + + Matrix tmp; + + tmp[1][1] = 1, tmp[1][2] = 1; + tmp[2][1] = 1, tmp[2][2] = 0; + + return binpow(tmp, n - 2)[1][1]; +} + +int n, m; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> m; + + cout << fib(std::__gcd(n, m)) % mod << endl; + + return 0; +}