結果

問題 No.2394 部分和乗総和
ユーザー erbowlerbowl
提出日時 2023-07-29 07:08:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 2,824 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 198,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 14:10:52
合計ジャッジ時間 4,391 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 18 ms
5,376 KB
testcase_14 AC 64 ms
5,376 KB
testcase_15 AC 66 ms
5,376 KB
testcase_16 AC 98 ms
5,376 KB
testcase_17 AC 180 ms
5,376 KB
testcase_18 AC 178 ms
5,376 KB
testcase_19 AC 181 ms
5,376 KB
testcase_20 AC 173 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;

#include <bits/stdc++.h>
using namespace std;
#define int long long

ll isqrt(ll N){
	ll sqrtN=sqrt(N)-1;
	while(sqrtN+1<=N/(sqrtN+1))sqrtN++;
	return sqrtN;
}


// modint
struct Fp {
    // static menber
    static int MOD;
    
    // inner value
    long long val;
    
    // constructor
    Fp() : val(0) { }
    Fp(long long v) : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    long long get() const { return val; }
    static int get_mod() { return MOD; }
    static void set_mod(int mod) { MOD = mod; }
    
    // arithmetic operators
    Fp operator - () const {
        return val ? MOD - val : 0;
    }
    Fp operator + (const Fp &r) const { return Fp(*this) += r; }
    Fp operator - (const Fp &r) const { return Fp(*this) -= r; }
    Fp operator * (const Fp &r) const { return Fp(*this) *= r; }
    Fp operator / (const Fp &r) const { return Fp(*this) /= r; }
    Fp& operator += (const Fp &r) {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    Fp& operator -= (const Fp &r) {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    Fp& operator *= (const Fp &r) {
        val = val * r.val % MOD;
        return *this;
    }
    Fp& operator /= (const Fp &r) {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    Fp pow(long long n) const {
        Fp res(1), mul(*this);
        while (n > 0) {
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    Fp inv() const {
        Fp res(1), div(*this);
        return res / div;
    }

    // other operators
    bool operator == (const Fp &r) const {
        return this->val == r.val;
    }
    bool operator != (const Fp &r) const {
        return this->val != r.val;
    }
    friend istream& operator >> (istream &is, Fp &x) {
        is >> x.val;
        x.val %= x.get_mod();
        if (x.val < 0) x.val += x.get_mod();
        return is;
    }
    friend ostream& operator << (ostream &os, const Fp &x) {
        return os << x.val;
    }
    friend Fp modpow(const Fp &r, long long n) {
        return r.pow(n);
    }
    friend Fp modinv(const Fp &r) {
        return r.inv();
    }
};

int Fp::MOD;


signed main(){
    ll n,m,b;
    std::cin >> n>>m>>b;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    using mint = Fp;
    mint::set_mod(b);

    mint sum = 1;   
    for (int i = 0; i < n; i++) {
        sum = sum + mint(m).pow(a[i])*sum;
    }
    std::cout << sum << std::endl;
}
0