結果
問題 | No.2394 部分和乗総和 |
ユーザー |
|
提出日時 | 2023-07-30 17:48:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 192 ms / 2,000 ms |
コード長 | 2,671 bytes |
コンパイル時間 | 1,808 ms |
コンパイル使用メモリ | 175,640 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 12:58:49 |
合計ジャッジ時間 | 3,672 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
// STLのインクルード#include <bits/stdc++.h>using namespace std;// // ACLのインクルード(デフォルトはコメントアウト)// #include <atcoder/all>// using namespace atcoder;// for文の略記#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)// vectorのソート#define all(x) x.begin(), x.end()// 型の略記 (競プロならでは)using ll = long long;using pii = pair<int, int>;using pll = pair<long long, long long>;using vi = vector<int>;using vl = vector<long long>;using vs = vector<string>;using vc = vector<char>;using vpii = vector<pair<int, int>>;using vpll = vector<pair<long long, long long>>;using vpsi = vector<pair<string, int>>;using vvi = vector<vector<int>>;using vvpii = vector<vector<pair<int, int>>>;using vvl = vector<vector<long long>>;using vvc = vector<vector<char>>;// MOD計算で使う#define MOD 1000000007#define MOD2 998244353// YES-NOで答える質問で使う(fがTrueならYes)void cout_yn(bool f){if(f)cout << "Yes" << endl;else cout << "No" << endl;}// 木の前順走査void dfs_preorder(int v, vvi &tree, vi &output){output.push_back(v);rep(i, tree[v].size()){dfs_preorder(tree[v][i], tree, output);}}// 木の後順走査void dfs_postorder(int v, vvi &tree, vi &output){rep(i, tree[v].size()){dfs_preorder(tree[v][i], tree, output);}output.push_back(v);}// n頂点m辺の無向グラフを隣接リストで受け取る.// 頂点番号は1-indexedとして入力される想定.vector<vector<int>> input_undir_graph(int n, int m){int a, b;vector<vector<int>> g(n);rep(i, m){cin >> a >> b;a--, b--;g[a].push_back(b); // a->b へ向かう辺g[b].push_back(a); // b->a へ向かう辺}return g;}// n頂点m辺の有向グラフを隣接リストで受け取る.// 頂点番号は1-indexedとして入力される想定.vector<vector<int>> input_dir_graph(int n, int m){int a, b;vector<vector<int>> g(n);rep(i, m){cin >> a >> b;a--, b--;g[a].push_back(b); // a->b へ向かう辺}return g;}ll modpow(ll x, ll n, ll p) {ll ret = 1;while(n > 0) {if(n & 1) ret = (ret * x) % p;x = (x * x) % p;n >>= 1;}return ret;}// main関数int main(void){ll n, m, b;cin >> n >> m >> b;m %= b;vl a(n);rep(i, n)cin >> a[i];sort(all(a));ll ans = 1;rep(i, n){ans = ans * (1LL + modpow(m, a[i], b) % b) % b;}cout << (ans + b) % b << endl;return 0;}