結果

問題 No.2394 部分和乗総和
ユーザー 河城白露河城白露
提出日時 2023-07-28 22:21:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 82,656 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 19:29:33
合計ジャッジ時間 2,289 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define ll long long
#define db double
using namespace std;
const ll N = 1e5 + 100;
ll tt,n,m,b,dp[N];
ll ksm(ll p,ll q) {
	ll res = 1;
	if (p == 0) {
		return 0;
	}
	while(q) {
		if (q & 1) {
			res *= p;
			res %= b;
		}
		p *= p;
		p %= b;
		q /= 2;
	}
	return res;
}
void solve() {
	scanf("%lld%lld%lld",&n,&m,&b);
	m %= b;
	dp[0] = 1;
	for (ll i = 1;i <= n;i++) {
		ll x;
		scanf("%lld",&x);
		dp[i] = (dp[i - 1] * (ksm(m,x) + 1)) % b;
	}
	printf("%lld\n",dp[n]);
}
int main() {
	tt = 1;
	while(tt) {
		solve();
		tt--;
	}
	return 0;
}
0