#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const int N = 100;
int msize;
struct Mat {
  long long mat[N][N];
};
Mat operator*(Mat a, Mat b) {
  Mat c;
  memset(c.mat, 0, sizeof(c.mat));
  for (int k = 0; k < msize; ++k)
    for (int i = 0; i < msize; ++i)
      if (a.mat[i][k])
        for (int j = 0; j < msize; ++j)
          if (b.mat[k][j])
            c.mat[i][j] = (c.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % Mod;
  return c;
}
Mat operator^(Mat a, long long k) {
  Mat c;
  memset(c.mat, 0, sizeof(c.mat));
  for (int i = 0; i < msize; ++i) c.mat[i][i] = 1;
  for (; k; k >>= 1) {
    if (k & 1) c = c * a;
    a = a * a;
  }
  return c;
}
long long C[N][N];
long long pow2[N];
void calcu() {
  C[0][0] = 1;
  for (int i = 1; i <= 50; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;
  }
  pow2[0] = 1;
  for (int i = 1; i <= 50; i++) pow2[i] = pow2[i - 1] * 2 % Mod;
}
int main() {
  calcu();
  long long n;
  int k;
  while (~scanf("%I64d%d", &n, &k)) {
    msize = 2 * k + 3;
    Mat A;
    memset(A.mat, 0, sizeof(A.mat));
    A.mat[0][0] = A.mat[0][1] = 1;
    for (int i = 1; i <= k + 1; i++) {
      for (int j = i, t = 0; j <= k + 1; j++, t++)
        A.mat[i][j] = C[k - i + 1][t];
      for (int j = i + k + 1, t = 0; j < msize; j++, t++)
        A.mat[i][j] = C[k - i + 1][t] * pow2[t] % Mod;
    }
    for (int i = k + 2; i < msize; i++) A.mat[i][i - k - 1] = 1;
    A = A ^ (n - 1);
    long long ans = A.mat[0][0];
    for (int i = 1; i <= k + 1; i++)
      ans = (ans + A.mat[0][i] * pow2[k + 2 - i]) % Mod;
    for (int i = k + 2; i < msize; i++) ans = (ans + A.mat[0][i]) % Mod;
    printf("%I64d\n", ans);
  }
  return 0;
}
