【洛谷P2480】古代猪文
题目大意:求 \[ G^{\sum\limits_{d|N}\binom{n}{k}} mod\ \ 999911659 \] 题解:卢卡斯定理+中国剩余定理 利用卢卡斯定理求出指数和式对各个素模数的解,再利用中国剩余定理合并四个解即可。 也可以在枚举 N 的因子的过程中,对于计算的四个解直接进行中国剩余定理的合并,答案不变。 代码如下 #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 999911658; const LL md[] = {2, 3, 4679, 35617}; const int maxn = 40000; LL fac[maxn]; inline LL fpow(LL a, LL b, LL c) { LL ret = 1 % c; for (; b; b >>= 1, a = a * a % c) { if (b & 1) { ret = ret * a % c; } } return ret; } inline LL comb(LL x, LL y, LL p) { if (y > x) { return 0; } return fac[x] * fpow(fac[x - y], p - 2, p) % p * fpow(fac[y], p