期望得分:100+100+20=220

实际得分:100+95+20=215

 

T1 洛谷 P1306 斐波那契公约数

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
LL t[2][2],ans[2][2],r[2][2];
const int mod=1e8;
int gcd(int a,int b)
{
    return !b ? a : gcd(b,a%b);
}
void mul(LL a[2][2],LL b[2][2])
{
    memset(r,0,sizeof(r));
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            for(int k=0;k<2;k++)
                r[i][j]+=a[i][k]*b[k][j],r[i][j]%=mod;
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            a[i][j]=r[i][j];
}
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int p=gcd(a,b);
    t[0][0]=t[0][1]=t[1][0]=1;;
    ans[0][0]=ans[0][1]=1;
    if(p==2 || p==1) { printf("1"); return 0; }
    p-=2;
    while(p)
    {
        if(p&1) mul(ans,t);
        mul(t,t); p>>=1;
    }
    printf("%lld",ans[0][0]);
}
View Code

相关文章:

  • 2021-06-05
  • 2021-08-15
  • 2021-11-13
  • 2021-05-27
  • 2021-09-25
  • 2022-01-07
  • 2021-12-12
  • 2021-10-21
猜你喜欢
  • 2021-11-29
  • 2021-11-05
  • 2022-12-23
  • 2021-12-26
  • 2021-06-17
  • 2021-11-06
  • 2021-08-11
相关资源
相似解决方案