zoukankan      html  css  js  c++  java
  • 斐波那契公约数

    传送门:

    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cstdlib>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    #define ll long long
    #define re register
    const int N=4e4+10;
    const int M=4e4;
    const int mod=1e8;
    inline void read(int &a)
    {
        a=0;
        int d=1;
        char ch;
        while(ch=getchar(),ch>'9'||ch<'0')
            if(ch=='-')
                d=-1;
        a=ch^48;
        while(ch=getchar(),ch>='0'&&ch<='9')
            a=(a<<3)+(a<<1)+(ch^48);
        a*=d;
    }
    struct note
    {
        int a[5][5];
    
    }ans,a;
    inline void init()
    {
        for(re int i=1;i<=2;i++)
            ans.a[i][i]=1;
        a.a[1][1]=1;
        a.a[1][2]=1;
        a.a[2][1]=1;
    }
    note Mat(note x,note y)
    {
        note c;
        for(re int i=1;i<=2;i++)
            for(re int j=1;j<=2;j++)
                c.a[i][j]=0;
        for(re int i=1;i<=2;i++)
            for(re int j=1;j<=2;j++)
                for(re int k=1;k<=2;k++)
                    (c.a[i][j]+=1ll*x.a[i][k]*y.a[k][j]%mod)%=mod;
        return c;
    }
    inline int gcd(int a,int b)
    {
        return !b?a:gcd(b,a%b);
    }
    int main()
    {
        init();
        int n,m;
        read(n);
        read(m);
        int p=gcd(n,m);
        if(p<=2)
            return puts("1"),0;
        p-=2;
        while(p)
        {
            if(p&1)
                ans=Mat(ans,a);
            a=Mat(a,a);
            p>>=1;
        }
        printf("%d",(ans.a[1][1]+ans.a[1][2])%mod);
        return 0;
    }
  • 相关阅读:
    ASP Loading
    haproxy中两个常用的宏
    数字签名-摘要等
    haproxy内存管理-free_list原理
    haproxy-代码阅读-内存管理
    网卡中断不均衡处理
    TIME_WAIT 另一种解决方式 SO_LINGER
    HTTP报文格式
    TIME_WAIT过多及解决
    awk如何向shell传值
  • 原文地址:https://www.cnblogs.com/acm1ruoji/p/10952259.html
Copyright © 2011-2022 走看看