Chenyanxi0829
2024-11-20 22:45:33
发现人的最优策略肯定是先一直生成最后再一直发传单,接着发现一个人会生成当且仅当
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 1e5 + 5, B = 450, mod = 1e9 + 7;
int q, dp[B][kMaxN], c[B][kMaxN], t;
inline void A(int &x, int y) { x += y, x >= mod && (x -= mod); }
int main() {
ios::sync_with_stdio(0), cin.tie(0);
dp[1][0] = 1;
for (int i = 1; i * (i - 1) / 2 <= 100000; t = i, i++) {
}
for (int i = t; i >= 1; i--) {
for (int j = 0; j + i * (i - 1) / 2 <= 100000; j++) {
j >= 2 * i ? (dp[i][j] = dp[i + 1][j - i], A(dp[i][j], dp[i][j - i]), c[i][j] = c[i + 1][j - i], A(c[i][j], c[i][j - i]), 0) : (dp[i][j] = j, c[i][j] = 1);
}
}
cin >> q;
for (int i = 1, n, z; i <= q; i++) {
cin >> n >> z, cout << (1ll * z * dp[1][n / z] % mod + 1ll * n % z * c[1][n / z]) % mod << '\n';
}
return 0;
}