http://codeforces.com/contest/1117/problem/D
题意:n,m(1e18) ;有一些魔法石,一个魔法石可以分裂成m个普通宝石,每个宝石站一个单位空间;问有多少集合使得站n个空间;
思路:
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int maxn=2e5+9;
const int mod=1e9+7;template <class T>
inline void sc(T &ret)
{char c;ret = 0;while ((c = getchar()) < '0' || c > '9');while (c >= '0' && c <= '9'){ret = ret * 10 + (c - '0'), c = getchar();}
}ll n,m;
struct M
{ll a[109][109];M(){mem(a,0);}
};M Mmul(M x,M y)
{M res;for(int i=1;i<=m;i++){for(int j=1;j<=m;j++){for(int k=1;k<=m;k++){res.a[i][j]=res.a[i][j]+(x.a[i][k]*y.a[k][j])%mod;res.a[i][j]%=mod;}}}return res;
}M Mpower(M x,ll n)
{M res;for(int i=1;i<=m;i++){res.a[i][i]=1;}while(n){if(n&1){res=Mmul(res,x);}x=Mmul(x,x);n>>=1;}return res;
}int main()
{cin>>n>>m;if(n<m){cout<<1<<endl;return 0;}M s;for(int i=1;i<=m;i++){s.a[i][1]=1;}M t;t.a[1][1]=t.a[1][m]=1;for(int i=2;i<=m;i++){t.a[i][i-1]=1;}M ans;ans=Mpower(t,n-m+1);ans=Mmul(ans,s);cout<<ans.a[1][1]<<endl;return 0;
}