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()
- using namespace std;
- using ll = long long;
- const ll mod = 998244353;
- ll fpow(ll a, ll p) {
- ll ans = 1;
- while (p) {
- if (p & 1) {
- ans = (ans * a) % mod;
- }
- a = (a * a) % mod;
- p >>= 1;
- }
- return ans;
- }
- vector<ll> facts = {1};
- ll Fact(int n) {
- while (facts.size() <= n) {
- facts.push_back(facts.back() * facts.size() % mod);
- }
- return facts[n];
- }
- vector<ll> rev = {1};
- ll Rev(int n) {
- while (rev.size() <= n) {
- rev.push_back(rev.back() * fpow(rev.size(), mod - 2) % mod);
- }
- return rev[n];
- }
- ll C(int n, int m) {
- return (Fact(n) * Rev(m) % mod) * Rev(n - m) % mod;
- }
- ll CaclProb(int k, int n, int a, int b) {
- ll revB = fpow(b, mod - 2);
- ll p = a * revB % mod;
- ll res = C(n, k) * fpow(p, k) % mod;
- ll tmp = fpow((mod + b - a) * fpow(b, mod - 2) % mod, n - k);
- res = (res * tmp) % mod;
- ll tot = fpow(2, n);
- res = (res * fpow(tot, mod - 2)) % mod;
- return res;
- }
- void solve() {
- int n, a, b;
- cin >> n >> a >> b;
- vector<ll> ans(n + 1);
- ll tot = fpow(n - 1, n);
- ll totRev = fpow(tot, mod - 2);
- for (int k = 0; k <= n; k++) {
- // number of shoots
- ll cur = CaclProb(k, n, a, b);
- cout << k << ' ' << n << ' ' << cur << endl;
- for (int dead = (k > 0); dead <= k; dead++) {
- ll num = C(n, dead) * C(k, dead) % mod;
- ll curProb = num * totRev % mod;
- curProb *= cur;
- curProb %= mod;
- ans[n - dead] += curProb;
- ans[n - dead] %= mod;
- }
- }
- for (auto val: ans) {
- cout << val << '\n';
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement