Fork me on GitHub

白兔的式子 (组合)

题目

白兔的式子

解析

\(\binom{n-1}{m-1}a^{n-m}b^{m-1}\),发现数据是1e5,所以用阶乘求,至于有理数取余可以看这篇题解

代码

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 20;
const int mod = 998244353;
int t, n, m, a, b;
int jc[N];

template<class T>inline void read(T &x) {
    x = 0; int f = 0; char ch = getchar();
    while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    x = f ? -x : x;
    return;
}

void init(int n = 100010) {
	jc[0] = 1;
	for (int i = 1; i <= n; ++i) jc[i] = (jc[i - 1] * i) % mod;
}

int qpow(int a, int b) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod, b >>= 1;
	}
	return ans;
}

int C(int n, int m) {
	return (jc[n] * qpow((jc[n - m] * jc[m]) % mod, mod - 2)) % mod;
}

signed main() {
	init();
	read(t);
	
	while (t--) {
		read(a), read(b), read(n), read(m);
		cout << ((C(n - 1, m - 1) * qpow(a, n - m)) % mod * qpow(b, m - 1)) % mod << '\n';
	}
}
posted @ 2019-05-26 21:21  Chrety  阅读(313)  评论(0编辑  收藏  举报