#include <bits/stdc++.h>
using namespace std;
struct mat {
  long long a[83][83];
};
mat mult(mat &A, mat &B) {
  mat C;
  for (int i = 0; i < 83; i++) {
    for (int j = 0; j < 83; j++) {
      long long tmp = 0;
      for (int k = 0; k < 83; k++) {
        tmp = (tmp + A.a[i][k] * B.a[k][j]) % 1000000007;
      }
      C.a[i][j] = tmp;
    }
  }
  return C;
}
mat pow(mat &A, long long N) {
  int i, j;
  mat ans;
  for (i = 0; i < 83; i++) {
    for (j = 0; j < 83; j++) {
      ans.a[i][j] = ((i == j) ? 1 : 0);
    }
  }
  for (i = 62; i >= 0; i--) {
    if (N & (1LL << i)) break;
  }
  for (; i >= 0; i--) {
    ans = mult(ans, ans);
    if (N & (1LL << i)) ans = mult(ans, A);
  }
  return ans;
}
long long two[50];
long long C[50][50];
int main() {
  long long N;
  int K;
  cin >> N >> K;
  two[0] = 1;
  for (int i = 0; i < 49; i++) {
    two[i + 1] = two[i] * 2 % 1000000007;
  }
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < i + 1; j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
    }
  }
  mat A;
  for (int i = 0; i < 83; i++) {
    for (int j = 0; j < 83; j++) {
      A.a[i][j] = 0;
    }
  }
  A.a[82][82] = 1;
  for (int i = 0; i < 41; i++) {
    A.a[i + 41][i] = 1;
  }
  for (int i = 0; i < 41; i++) {
    for (int j = 0; j < 41; j++) {
      if (i <= j) {
        A.a[i][j + 41] = C[j][i] * two[j - i] % 1000000007;
        A.a[i + 41][j + 41] = C[j][i];
      }
    }
  }
  for (int i = 0; i < 41; i++) {
    A.a[82][i + 41] = (1 + two[i]) % 1000000007;
  }
  mat B = pow(A, N);
  long long ans = 0;
  for (int i = 41; i < 83; i++) {
    ans = (ans + B.a[i][K]) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}
