扔骰子问题 1
Description
有
现在投掷出这些骰子,请问恰好有
请你求出这个概率对
Solution
首先我们要从
其次,对于选出的
再其次,对于没有选出的
因此答案为:
Code
对于这三部分答案,可以分别来求:
-
组合数可以预处理阶乘和阶乘的逆元;
-
-
typedef long long LL;
const int N = 5e6 + 10;
int fpm(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1) res = (LL)res * a % P;
b >>= 1, a = (LL)a * a % P;
}
return res;
}
int T, n, m;
int k, res;
int fac[N], inv[N];
int p5[N]; // p5[i] = 5 ^ i
int inv6[N]; // inv6[i] = 6 ^ i 的逆元
void init(int n)
{
fac[0] = p5[0] = 1;
fup (i, 1, n)
fac[i] = (LL)fac[i - 1] * i % P;
inv[n] = fpm(fac[n], P - 2);
fdw (i, n - 1, 0)
inv[i] = (LL)inv[i + 1] * (i + 1) % P;
fup (i, 1, n)
p5[i] = (LL)p5[i - 1] * 5 % P;
inv6[n] = fpm(fpm(6, n), P - 2);
fdw (i, n - 1, 0)
inv6[i] = (LL)inv6[i + 1] * 6 % P;
}
int C(int n, int m)
{
return (LL)fac[n] * inv[m] % P * inv[n - m] % P;
}
int main()
{
init(N - 1);
puts("tou"); // 骰 念 tou
T = read();
while (T -- )
{
n = read(), m = read();
k = (LL)C(n, m) * inv6[m] % P * p5[n - m] % P * inv6[n - m] % P;
res ^= k;
}
write(res);
return 0;
}