思路:初看题意可能被吓到,不过肯定是不用求出第n,m个斐波那契数的,我是打表找规律发现gcd(f[n],f[m])=f[gcd(n,m)]的,所有莽了一发居然过了,看题解,证明很麻烦。。。
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
const ll mod = 1e8;
ll siz, n, m;
struct mtx {
ll x[2 + 1][2 + 1];
mtx() {
memset(x, 0, sizeof x);
}
};
mtx operator *(const mtx &a, const mtx &b) {
mtx c;
for(int i = 0; i < siz; i++)
for(int j = 0; j < siz; j++)
for(int k = 0; k < siz; k++)
c.x[i][j] = (c.x[i][j] + a.x[i][k] * b.x[k][j] % mod) % mod;
return c;
}
mtx operator ^(mtx a, ll k) {
mtx ret;
for(int i = 0; i < siz; ++i)
ret.x[i][i] = 1;
while(k) {
if(k & 1)
ret = ret * a;
a = a * a;
k >>= 1;
}
return ret;
}
int main() {
siz = 2;
cin >> n >> m;
n = __gcd(n, m);
if(n <= 2) {
cout << 1;
return 0;
}
mtx ak;
ak.x[0][0] = 1;
ak.x[0][1] = 1;
ak.x[1][0] = 1;
mtx w;
w = ak ^ (n - 2);
ll ans = (w.x[0][0] + w.x[0][1]) % mod;
cout << ans;
return 0;
}