#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; typedef long double LD; #define pb push_back #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define counti(x) (__builtin_popcount(x)) #define countl(x) (__builtin_popcountll(x)) #define rep(i, n) for (int (i) = 0; (i) < (int)(n); ++(i)) #define X first #define Y second template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } int get() { char c; while (c = getchar(), (c < '0' || c > '9') && (c != '-')); bool flag = (c == '-'); if (flag) c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - 48; c = getchar(); } return flag ? -x : x; } void output(int x) { if (x < 0) { putchar('-'); x = -x; } int len = 0, data[20]; while (x) { data[len++] = x % 10; x /= 10; } if (!len) data[len++] = 0; while (len--) putchar(data[len] + 48); putchar('\n'); } const int MX = 150; const int MOD = 1000000007; LL val[MX][MX], cnt[MX][MX], A[MX][MX], B[MX][MX]; int deg; void multi(LL v[MX][MX], LL v1[MX][MX]) { memcpy(A, v, sizeof A); memcpy(B, v1, sizeof B); int i, j, k; for (i = 0; i < deg; i++) { for (j = 0; j < deg; j++) { v[i][j] = 0; for (k = 0; k < deg; k++) { v[i][j] += A[i][k] * B[k][j] % MOD; } v[i][j] %= MOD; } } } int main() { int n, m; int Tcase; while (scanf("%d%d", &n, &m) == 2) { deg = 1 << m; memset(val, 0, sizeof val); if (n == 1) { printf("%d\n", deg); continue; } memset(val, 0, sizeof val); int i, j, k; for (i = 0; i < deg; i++) { for (j = 0; j < deg; j++) { for (k = 0; k < m; k++) if (i & bit(k)) { int x = k - 1; if (x >= 0 && (bit(x) & j) != 0) { if ((i & bit(x)) == 0 && (j & bit(k)) == 0) { break; } } x = k + 1; if (x < m && (bit(x) & j) != 0) { if ((i & bit(x)) == 0 && (j & bit(k)) == 0) { break; } } } if (k == m) val[j][i] = 1; } } memset(cnt, 0, sizeof cnt); for (i = 0; i < deg; i++)cnt[i][i] = 1; n--; while (n) { if (n & 1) { multi(cnt, val); } n >>= 1; multi(val, val); } int res = 0; for (i = 0; i