Problem p02992 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;

  vector<int> quotients(1, 0);
  for (int i = 1; i <= sqrt(n) + 1; ++i) {
    quotients.push_back(n / i);
    quotients.push_back(n / (n / i));
  }
  sort(quotients.begin(), quotients.end());
  quotients.erase(unique(quotients.begin(), quotients.end()), quotients.end());
  int m = quotients.size();

  vector<int> inv_quotients_idx(m, -1);
  {
    int j = m - 1;
    for (int i = 1; i < m; ++i) {
      while (i <= j && quotients[i] * quotients[j] > n)
        --j;
      if (i > j)
        break;
      inv_quotients_idx[i] = j;
      inv_quotients_idx[j] = i;
    }
  }

  vector<vector<ll>> dp(k + 1, vector<ll>(m, 0));
  for (int j = 1; j < m; ++j)
    dp[0][j] = quotients[j];
  for (int i = 1; i < k; ++i) {
    for (int j = 1; j < m; ++j) {
      dp[i][j] = (dp[i - 1][inv_quotients_idx[j]] *
                  (quotients[j] - quotients[j - 1])) %
                 MOD;
    }

    for (int j = 1; j < m; ++j) {
      dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }

  cout << dp[k - 1][m - 1] << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;

  vector<int> quotients(1, 0);
  for (int i = 1; i <= min(n, ll(sqrt(n)) + 1); ++i) {
    quotients.push_back(n / i);
    quotients.push_back(n / (n / i));
  }
  sort(quotients.begin(), quotients.end());
  quotients.erase(unique(quotients.begin(), quotients.end()), quotients.end());
  int m = quotients.size();

  vector<int> inv_quotients_idx(m, -1);
  {
    int j = m - 1;
    for (int i = 1; i < m; ++i) {
      while (i <= j && quotients[i] * quotients[j] > n)
        --j;
      if (i > j)
        break;
      inv_quotients_idx[i] = j;
      inv_quotients_idx[j] = i;
    }
  }

  vector<vector<ll>> dp(k + 1, vector<ll>(m, 0));
  for (int j = 1; j < m; ++j)
    dp[0][j] = quotients[j];
  for (int i = 1; i < k; ++i) {
    for (int j = 1; j < m; ++j) {
      dp[i][j] = (dp[i - 1][inv_quotients_idx[j]] *
                  (quotients[j] - quotients[j - 1])) %
                 MOD;
    }

    for (int j = 1; j < m; ++j) {
      dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }

  cout << dp[k - 1][m - 1] << endl;
}