社区讨论

0分求助

P1306斐波那契公约数参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@lo8ed9vv
此快照首次捕获于
2023/10/27 17:14
2 年前
此快照最后确认于
2023/10/27 17:14
2 年前
查看原帖
CPP
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
const int maxn=10;
const long long mod=1e8;
using namespace std;
long long n,m;
struct M{
    long long c[maxn][maxn];
}I,A,F;
M operator * (const M& x,const M& y){
    M ans;
    for(int i=1;i<maxn;i++)
        for(int j=1;j<maxn;j++)
            ans.c[i][j]=0;
    for(int i=1;i<maxn;i++){
        for(int j=1;j<maxn;j++){
            for(int k=1;k<maxn;k++){
                ans.c[i][j]+=x.c[i][k]*y.c[k][j]%mod;
                ans.c[i][j]%=mod;
            }
        }
    }
    return ans;
}

long long gcd(long long x,long long y){
    if(y==0)return x;
    return gcd(y,x%y);
}
int main(){

    cin>>n>>m;
    n=n-1;
    A.c[1][1]=A.c[1][2]=A.c[2][1]=1;
    I.c[1][1]=I.c[2][2]=1;
    while(n>0){
        if(n&1){
            I=I*A;
        }
        A=A*A;
        n=n>>1;
    }
    n=(I.c[1][1]%mod+I.c[1][2]%mod)%mod;
    m=m-1;
    memset(A.c,0,sizeof(A.c));
    memset(I.c,0,sizeof(I.c));
    A.c[1][1]=A.c[1][2]=A.c[2][1]=1;
    I.c[1][1]=I.c[2][2]=1;
    while(m>0){
        if(m&1){
            I=I*A;
        }
        A=A*A;
        m=m>>1;
    }
    m=(I.c[1][1]%mod+I.c[1][2]%mod)%mod;
    cout<<gcd(n,m)<<endl;
    //cout<<n<<" "<<m<<endl;
    return 0;
}

回复

5 条回复,欢迎继续交流。

正在加载回复...