#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int K = 85;
long long ncr[K][K];
inline void pre() {
  memset(ncr, 0, sizeof(ncr));
  ncr[0][0] = 1;
  for (int n = 1; n < K; n++) {
    ncr[n][0] = 1;
    for (int r = 1; r <= n; r++) {
      ncr[n][r] = (ncr[n - 1][r] + ncr[n - 1][r - 1]) % mod;
    }
  }
}
inline void product(long long A[K][K], long long B[K][K], long long C[K][K],
                    int sz) {
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      C[i][j] = 0;
      for (int k = 0; k < sz; k++) {
        C[i][j] += A[i][k] * B[k][j] % mod;
        if (C[i][j] >= mod) C[i][j] -= mod;
      }
    }
  }
}
inline void power(long long A[K][K], long long n, long long B[K][K], int sz) {
  long long C[K][K];
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      B[i][j] = (i == j);
    }
  }
  while (n) {
    if (n & 1) {
      product(B, A, C, sz);
      for (int i = 0; i < sz; i++) {
        for (int j = 0; j < sz; j++) {
          B[i][j] = C[i][j];
        }
      }
    }
    product(A, A, C, sz);
    for (int i = 0; i < sz; i++) {
      for (int j = 0; j < sz; j++) {
        A[i][j] = C[i][j];
      }
    }
    n >>= 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(32);
  pre();
  long long A[K][K];
  long long n;
  int k;
  cin >> n >> k;
  memset(A, 0, sizeof(A));
  if (n == 1) {
    cout << 1 << endl;
    exit(0);
  }
  if (n == 2) {
    long long ret = (1LL << (k + 1)) + 1;
    ret %= mod;
    cout << ret << endl;
    exit(0);
  }
  int sz = 2 * k + 3;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      A[i][j] = ncr[i][j];
      A[i][j + k + 1] = ncr[i][j] * ((1LL << (i - j)) % mod) % mod;
    }
    A[i + k + 1][i] = 1;
    A[i][2 * k + 2] = (1 + (1LL << i)) % mod;
  }
  A[2 * k + 2][2 * k + 2] = 1;
  long long B[K][K];
  power(A, n - 1, B, sz);
  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    ans += B[k][i];
  }
  ans += B[k][2 * k + 2];
  ans %= mod;
  cout << ans << endl;
  return 0;
}
