Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //link : https://codeforces.com/contest/1117/submission/50110620
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- const int SIZE=105;
- const int mod=(int)1e9+7;
- struct Mat{
- ll v[SIZE][SIZE];
- Mat(){
- memset(v,0,sizeof(v));
- }
- };
- Mat mulmat(Mat &a,Mat &b,int n=SIZE)
- {
- Mat ret;
- int i,j,k;
- for(i=1;i<=n;i++){
- for(j=1;j<=n;j++){
- for(k=1;k<=n;k++){
- ret.v[i][j]=(ret.v[i][j]+(a.v[i][k]*b.v[k][j])%mod)%mod;
- }
- }
- }
- return ret;
- }
- Mat powmat(Mat a,ll p,int n=SIZE)
- {
- Mat ret;
- for(int i=1;i<=n;i++)ret.v[i][i]=1;
- while(p){
- if(p%2)ret=mulmat(ret,a,n);
- a=mulmat(a,a,n);
- p>>=1;
- }
- return ret;
- }
- void print(Mat a,int n=SIZE)
- {
- for(int i=1;i<=n;i++){
- for(int j=1;j<=n;j++)
- cout<<a.v[i][j]<<' ';
- cout<<endl;
- }
- }
- int main()
- {
- ll n=3,k=2;
- int i,j;
- cin>>n>>k;
- if(n<k)return cout<<1<<endl,0;
- Mat now;
- for(i=1;i<k;i++)now.v[i][i+1]=1;
- now.v[1][1]=now.v[k][1]=1;
- now=powmat(now,n-k+1,k);
- //print(now,k);
- ll ans=0;
- for(i=1;i<=k;i++)ans=(ans+now.v[i][1])%mod;
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement