1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 5e6 + 10; 5 ll fac[N], sv[N], inv[N], a[N]; 6 ll n, p, k; 7 void read(ll &x) { 8x = 0; int f = 1; char ch = getchar(); 9while (ch < '0' || ch >'9') {if (ch == '-') f = -1; ch = getchar();}10while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();11x *= f;12 }13 ll quickpow(ll x, ll y) {14ll ans = 1;15while (y) {16if (y & 1) ans = ans * x % p;17x = x * x % p;18y >>= 1;19}20return ans % p;21 }22 signed main() {23read(n), read(p), read(k);24fac[0] = 1;25for (int i = 1; i <= n; i ++) {26read(a[i]);27fac[i] = fac[i - 1] * a[i] % p;28}29sv[n] = quickpow(fac[n], p - 2);30for (int i = n; i >= 1; i --) sv[i - 1] = sv[i] * a[i] % p;31ll tmp = 1, ans = 0;32for (int i = 1; i <= n; i ++) {33tmp = (tmp * k) % p;34ans = (ans + ((sv[i] * fac[i - 1] % p)) * tmp) % p;35}36printf("%lld\n", ans);37return 0;38 }【P5431 【模板】乘法逆元 2】
推荐阅读
- 斗罗大陆:武魂觉醒荒野行纪1
- 实用帖:从成都到稻城亚丁,最全自驾游攻略
- 狼人杀怎样才能玩的好(狼人杀怎么玩难度高)
- 狼人杀全面教程(狼人杀的教程)
- 我该怎么做(我该怎么做才能被你偏爱)
- realmev15耳机插孔在哪里_realmev15耳机孔
- 做什么和怎么做的区别(会做事和能做事的区别)
- 无悔华夏王翦阵容怎么搭配
- 送老公礼物排行榜2019,这几款实用又上档次
- steam如何强制退款(steam上可以退款吗)