Problem:
Score : 600 points

Problem Statement

Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.

Constraints

1\leq N\leq 10^9

1 2\leq K\leq 100 (fixed at 21:33 JST)

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of sequences, modulo 10^9+7.

Sample Input 1

3 2

Sample Output 1

5

(1,1), (1,2), (1,3), (2,1), and (3,1) satisfy the condition.

Sample Input 2

10 3

Sample Output 2

147

Sample Input 3

314159265 35

Sample Output 3

457397712

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>

using namespace std;

#define int long long
int const maxc = 100005;
int mod = 1e9 + 7;
int dp[105][maxc], dp1[105][maxc], pref[maxc], pref1[maxc];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector < pair < int, int > > a;
    for (int i = maxc; i <= n; ++i) {
        int lef = i, righ = n + 1;
        while (righ - lef > 1) {
            int mid = (righ + lef) / 2;
            if (n / i == n / mid) lef = mid;
            else righ = mid;
        }
        a.push_back({i, lef});
        i = lef;
    }
    for (int i = 1; i < min(maxc, n + 1); ++i) dp[1][i] = 1;
    for (int j = 0; j < (int)a.size(); ++j) dp1[1][j] = a[j].second - a[j].first + 1;
    for (int i = 2; i <= k; ++i) {
        for (int j = 1; j < min(maxc, n + 1); ++j) pref[j] = pref[j - 1] + dp[i - 1][j];
        for (int j = 1; j <= (int)a.size(); ++j) pref1[j] = pref1[j - 1] + dp1[i - 1][j - 1];
        for (int j = 1; j < min(maxc, n + 1); ++j) {
            /*for (int lst = 1; lst * j <= n && lst < min(maxc, n + 1); ++lst) {
                dp[i][j] += dp[i - 1][lst];
            }*/
            int lst = min({n / j, n, maxc - 1});
            dp[i][j] += pref[lst];
            /*for (int lst = 0; lst < (int)a.size(); ++lst) {
                if (a[lst].first * i <= n && a[lst].first * i > n) {
                    cout << "WA";
                    exit(0);
                }
                if (a[lst].first * i <= n) dp[i][j] += dp1[i][lst];
            }*/
            int lef = -1, righ = (int)a.size();
            while (righ - lef > 1) {
                int mid = (righ + lef) / 2;
                if (a[mid].first * j <= n) lef = mid;
                else righ = mid;
            }
            dp[i][j] += pref1[lef + 1];
            dp[i][j] %= mod;
        }
        for (int j = 0; j < (int)a.size(); ++j) {
            /*for (int lst = 1; lst < min(maxc, n + 1); ++lst) {
                if (a[j].first * lst <= n && a[j].second * lst > n) {
                    cout << "WA";
                    exit(0);
                }
                if (a[j].first * lst <= n) dp1[i][j] += dp[i - 1][lst] * (a[j].second - a[j].first + 1);
            }*/
            dp1[i][j] += (a[j].second - a[j].first + 1) * (pref[n / a[j].first] % mod);
            dp1[i][j] %= mod;
        }
    }
    int ans = 0;
    for (int i = 0; i < maxc; ++i) ans += dp[k][i] + dp1[k][i];
    cout << ans % mod << '\n';
    return 0;
}