#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b) {
  if (a + b < MOD) return a + b;
  return a + b - MOD;
}
int sub(int a, int b) {
  if (a - b >= 0) return a - b;
  return a - b + MOD;
}
int mult(int a, int b) { return (long long)a * b % MOD; }
vector<vector<int>> operator*(const vector<vector<int>> &a,
                              const vector<vector<int>> &b) {
  int n1 = a.size();
  int m1 = a[0].size();
  int n2 = b.size();
  int m2 = b[0].size();
  assert(m1 == n2);
  int n = n1;
  int m = m2;
  vector<vector<int>> c = vector<vector<int>>(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m1; k++) {
        c[i][j] = add(c[i][j], mult(a[i][k], b[k][j]));
      }
    }
  }
  return c;
}
vector<vector<int>> matPow(vector<vector<int>> a, long long b) {
  int n = a.size();
  vector<vector<int>> ans = vector<vector<int>>(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    ans[i][i] = 1;
  }
  while (b > 0) {
    if (b & 1 == 1) {
      ans = ans * a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
const int MX = 45;
int comb[MX][MX];
int pot[MX];
int fastPow(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1 == 1) {
      ans = mult(ans, a);
    }
    a = mult(a, a);
    b >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  pot[0] = 1;
  for (int i = 1; i < MX; i++) {
    pot[i] = mult(pot[i - 1], 2);
  }
  for (int i = 0; i < MX; i++) {
    comb[i][i] = 1;
    comb[i][0] = 1;
  }
  for (int i = 1; i < MX; i++) {
    for (int j = 1; j < MX; j++) {
      comb[i][j] = add(comb[i - 1][j - 1], comb[i - 1][j]);
    }
  }
  long long n;
  int k;
  cin >> n >> k;
  vector<vector<int>> M =
      vector<vector<int>>(2 * (k + 1) + 1, vector<int>(2 * (k + 1) + 1, 0));
  for (int i = 0; i <= k; i++) {
    M[i][i + k + 1] = 1;
  }
  M[2 * (k + 1)][2 * (k + 1)] = 1;
  M[2 * (k + 1)][2 * (k + 1) - 1] = 1;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      M[i + k + 1][j] = mult(comb[i][j], pot[i - j]);
      M[i + k + 1][j + k + 1] = comb[i][j];
    }
  }
  vector<vector<int>> B =
      vector<vector<int>>(2 * (k + 1) + 1, vector<int>(1, 0));
  int val = 2;
  for (int i = 0; i <= k; i++) {
    B[i][0] = 1;
    B[i + k + 1][0] = val;
    val = mult(val, 2);
  }
  B[2 * (k + 1)][0] = 1;
  vector<vector<int>> ans = matPow(M, n - 1) * B;
  cout << ans[2 * (k + 1)][0] << "\n";
  return 0;
}
