Paste: small product
Author: | inszva |
Mode: | c++ |
Date: | Thu, 26 Aug 2021 05:48:21 |
Plain Text |
#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e5+7;
constexpr int M = 1e9+7;
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int long long
#define pii pair<int, int>
#define cpii const pair<int, int>&
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
#ifdef int
#define INF 0x3f3f3f3f3f3f3f3f
#define INF2 (int)(0xcfcfcfcfcfcfcfcf)
#else
#define INF 0x3f3f3f3f
#define INF2 0xcfcfcfcf
#endif
signed main() {
fastio
int n, k;
cin >> n >> k;
int root = 1;
while ((root+1)*(root+1) <= n) root++;
vector<vector<int>> dp(k+2, vector<int>(root+2, 0));
vector<vector<int>> dp2(k+2, vector<int>(root+2, 0));
dp[0][1] = 1;
auto add = [](int& x, int y) {
if (y < 0) y = y + M;
x = x + y;
if (x >= M) x -= M;
};
for (int i = 0; i <= k; i++) {
for (int j = 1; j <= root; j++)
add(dp[i][j], dp[i][j-1]), cout << i << " " << j << ":" << dp[i][j] << endl;
for (int j = root; j >= 1; j--)
add(dp2[i][j-1], dp2[i][j]), cout << i << " " << j << ":" << dp2[i][j] << endl;;
for (int j = 1; j <= root; j++) {
add(dp2[i+1][j], dp[i][j]);
add(dp2[i+1][0], -dp[i][j]);
add(dp[i+1][1], dp[i][j]);
add(dp[i+1][root+1], -dp[i][j]);
}
for (int j = root, l = root+1; j >= 1; j--) {
int r = n / j;
int cnt = r - l + 1;
add(dp[i+1][1], dp2[i][j] * cnt % M);
add(dp[i+1][j+1], -(dp2[i][j] * cnt % M));
l = r + 1;
}
}
cout << dp[k+1][1] << "\n";
return 0;
}
New Annotation