超级小帅童tj
2024-07-07 12:14:55
发布于:广东
38阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int MOD = 100000000;
typedef vector<vector<long long>> Matrix;
Matrix multiply(const Matrix& a, const Matrix& b) {
int n = a.size();
Matrix c(n, vector<long long>(n, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
}
}
}
return c;
}
Matrix matrixPower(Matrix base, long long exp) {
int n = base.size();
Matrix result(n, vector<long long>(n, 0));
for (int i = 0; i < n; ++i) {
result[i][i] = 1;
}
while (exp > 0) {
if (exp % 2 == 1) {
result = multiply(result, base);
}
base = multiply(base, base);
exp /= 2;
}
return result;
}
long long fibonacci(long long n) {
if (n == 0) return 0;
if (n == 1) return 1;
Matrix base = {{1, 1}, {1, 0}};
Matrix result = matrixPower(base, n - 1);
return result[0][0];
}//肥波内切
int main() {
long long n, m;
cin >> n >> m;
long long g = __gcd(n, m);
cout << fibonacci(g) << endl;
return 0;
}
全部评论 1
菜
2024-07-07 来自 广东
0爽,哥哥的**真好吃
2024-07-07 来自 广东
0?
2024-07-07 来自 广东
0爽了
2024-07-07 来自 广东
0
有帮助,赞一个