萌新爆零求调
查看原帖
萌新爆零求调
610557
shinzanmonoszm 妹妹楼主2023/3/13 20:01
#include<iostream>
using ll = long long;
const int sz = 5e6 + 10;
ll pre[sz], suf[sz], arr[sz], mod, up;
ll qpow(ll base, int exp) {
    ll ans = 1;
    while (exp) {
        if (exp & 1) ans = ans * base % mod;
        base = base * base % mod, exp >>= 1;
    }
    return ans;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll k;
    int n;
    std::cin >> n >> mod >> k;
    pre[0] = 1;
    for (int i = 1; i <= n; i++) 
        std::cin >> arr[i], pre[i] = arr[i] * pre[i - 1] % mod;
    suf[n + 1] = 1;
    for (int i = n; i; i--) 
        suf[i] = arr[i] * suf[i + 1];
    for (ll i = 1, p = k; i <= n; i++, p = p * k % mod) 
        up = (up + p * pre[i - 1] % mod * suf[i + 1] % mod) % mod;
    std::cout << up * qpow(pre[n], mod - 2) % mod << "\n";
    return 0;
}
2023/3/13 20:01
加载中...