# Codeforces 227E/226C Anniversary Fibonacci sequence properties + matrix fast power

This is the background of my blog Let's take a look at the problem

## Topic translation

In this paper, we give the maximum common divisor of Fibonacci number with these numbers as subscripts
Output the value of maximum modulus m

## Woo Mao

I'm very glad to see it. I think it's very useful. First, let's consider a property of Fibonacci sequence F(n)F(n):
gcd(F(a),F(b))=F(gcd(a,b))gcd(F(a),F(b))=F(gcd(a,b))
I remember where I came from to know the nature?
luogu p1306 Fibonacci common divisor
Then just find the maximum xx so that the multiple of xx is greater than or equal to kk in [l,r][l,r]
Guess if this xx can be divided into two parts?
I have to make a meal of myself here
I even wrote two points for things that couldn't be divided, and at first thought that my two points were withered, then I found that I couldn't be divided at all, and I adjusted it for five hours!
According to the data range, we use the enumeration of n − √ n. since we only need the maximum value, we only need to judge whether the multiple of I I and r/ir/i is greater than or equal to kk for each ii within r √ r
In this way, we can find ansans. The answer is the Fibonacci number of the first ansans. We can use the fast power of matrix

```#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
int x=0,f=1;char c=gc();
for (;!isdigit(c);c=gc()) f^=c=='-';
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return f?x:-x;
}
template <typename mitsuha>
x=0;int f=1;char c=gc();
for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
if (!~c) return 0;
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return x=f?x:-x,1;
}
template <typename mitsuha>
inline int write(mitsuha x){
if (!x) return 0&pc(48);
if (x<0) x=-x,pc('-');
int bit,i,p=0;
for (;x;x/=10) bit[++p]=x%10;
for (i=p;i;--i) pc(bit[i]+48);
return 0;
}
inline char fuhao(){
char c=gc();
for (;isspace(c);c=gc());
return c;
}
}using namespace chtholly;
using namespace std;
ll l,r,k;

bool judge(ll x){
return r/x-(l-1)/x>=k;
}

struct juzhen{
ll m;
void clearit(){
memset(m,0,sizeof m);
m=m=1;
}
void clear(){memset(m,0,sizeof m);}
juzhen operator *(const juzhen &b) const{
int i,j,k;
juzhen ans;ans.clear();
for (i=1;i<3;++i){
for (j=1;j<3;++j){
for (k=1;k<3;++k){
ans.m[i][j]=(ans.m[i][j]+m[i][k]*b.m[k][j])%mod;
}
}
}return ans;
}
};

juzhen operator ^(juzhen a,ll b){
juzhen c;c.clearit();
for (;b;b>>=1,a=a*a) if (b&1) c=c*a;
return c;
}

int main(){
ll ans=0;
for (ll i=1;i*i<=r;++i){
if (judge(i)) ans=max(ans,i);
if (judge(r/i)) ans=max(ans,r/i);
}
juzhen tmp;
tmp.clear();
tmp.m=tmp.m=tmp.m=1;
tmp=tmp^ans-1;
write((tmp.m+mod)%mod);
}
/*
gcd(F(a),F(b))=F(gcd(a,b));
*/```

Thank you

Posted on Fri, 31 Jan 2020 19:55:17 -0500 by taboo