Problem p02992 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
string char_to_str(char c) {
  string tem(1, c);
  return tem;
}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long

/////////////

signed main() {
  fastio;
#ifdef ANIKET_GOYAL
  freopen("inputf.in", "r", stdin);
  freopen("outputf.in", "w", stdout);
#endif
  int n, k;
  cin >> n >> k;
  int r[50000][2];
  int x = 0;
  int la;
  vector<int> v;
  for (int i = 1; i * i <= n; ++i) {
    r[x][0] = i;
    r[x][1] = i;
    ++x;
    la = i;
    v.push_back(1);
  }
  // cout<<"!"<<endl;;
  ++la;
  while (la <= n) {
    r[x][0] = la;
    int va = n / la;
    if (va == 1) {
      r[x][1] = n;
      la = n + 1;
    } else {
      r[x][1] = n / (va);
      la = n / (va) + 1;
    }
    v.push_back(1);
    ++x;
  }
  int mo = 1000000007;
  for (int i = 0; i < x; ++i) {
    // cout<<r[i][0]<<" "<<r[i][1]<<"\n";
  }
  for (int i = 2; i <= k; ++i) {
    for (int j = 1; j < v.size(); ++j) {
      v[j] = (v[j] * (r[j][1] - r[j][0] + 1)) % mo + v[j - 1];
      v[j] %= mo;
    }
    reverse(v.begin(), v.end());
  }
  int ans = 0;
  for (int i = 0; i < x; ++i) {
    ans += (v[i] * (r[i][1] - r[i][0] + 1)) % mo;
    ans %= mo;
    // cout<<r[i]
    // cout<<ans<<"\n";
    // ans%=mo;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
string char_to_str(char c) {
  string tem(1, c);
  return tem;
}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long

/////////////

signed main() {
  fastio;
#ifdef ANIKET_GOYAL
  freopen("inputf.in", "r", stdin);
  freopen("outputf.in", "w", stdout);
#endif
  int n, k;
  cin >> n >> k;
  int r[500000][2];
  int x = 0;
  int la;
  vector<int> v;
  for (int i = 1; i * i <= n; ++i) {
    r[x][0] = i;
    r[x][1] = i;
    ++x;
    la = i;
    v.push_back(1);
  }
  // cout<<"!"<<endl;;
  ++la;
  while (la <= n) {
    r[x][0] = la;
    int va = n / la;
    if (va == 1) {
      r[x][1] = n;
      la = n + 1;
    } else {
      r[x][1] = n / (va);
      la = n / (va) + 1;
    }
    v.push_back(1);
    ++x;
  }
  int mo = 1000000007;
  for (int i = 0; i < x; ++i) {
    // cout<<r[i][0]<<" "<<r[i][1]<<"\n";
  }
  for (int i = 2; i <= k; ++i) {
    for (int j = 1; j < v.size(); ++j) {
      v[j] = (v[j] * (r[j][1] - r[j][0] + 1)) % mo + v[j - 1];
      v[j] %= mo;
    }
    reverse(v.begin(), v.end());
  }
  int ans = 0;
  for (int i = 0; i < x; ++i) {
    ans += (v[i] * (r[i][1] - r[i][0] + 1)) % mo;
    ans %= mo;
    // cout<<r[i]
    // cout<<ans<<"\n";
    // ans%=mo;
  }
  cout << ans;
}