Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(), (x).end()
- #define itn int
- #define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())
- using namespace std;
- inline int nxt() {
- int x;
- cin >> x;
- return x;
- }
- int mod;
- const int N = 211'111;
- long long inv[N], fact[N], invfact[N];
- inline long long C(int n, int k) {
- return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
- }
- long long ans[N];
- int n;
- void rec(int sum, int mul, int cur, int cnt, int spent, long long val) {
- if (sum + (n - spent) < mul) {
- return;
- }
- if (sum + (n - spent) >= mul && sum < mul) {
- ans[mul - sum + spent] += C(mul - sum + spent, spent) * val % mod;
- }
- while (sum + cur + n >= 1ll * cur * mul) {
- rec(sum + cur, mul * cur, cur, cnt + 1, spent + 1, val * (spent + 1) % mod * inv[cnt + 1] % mod);
- ++cur;
- cnt = 0;
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- n = nxt();
- mod = nxt();
- fact[0] = fact[1] = invfact[0] = invfact[1] = inv[1] = 1;
- for (int i = 2; i <= n; ++i) {
- inv[i] = mod - (mod / i) * inv[mod % i] % mod;
- fact[i] = fact[i - 1] * i % mod;
- invfact[i] = invfact[i - 1] * inv[i] % mod;
- }
- for (int i = 2; i * i <= 2 * i + n; ++i) {
- rec(i, i, i, 1, 1, 1);
- }
- ans[2] += 1;
- for (int i = 2; i <= n; ++i) {
- cout << ans[i] % mod << " ";
- }
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement