結果

問題 No.1161 Many Powers
ユーザー misora192misora192
提出日時 2020-08-14 08:44:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 162,992 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 18:11:54
合計ジャッジ時間 4,152 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 13 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 90 ms
5,376 KB
testcase_09 AC 106 ms
5,376 KB
testcase_10 AC 43 ms
5,376 KB
testcase_11 AC 78 ms
5,376 KB
testcase_12 AC 40 ms
5,376 KB
testcase_13 AC 121 ms
5,376 KB
testcase_14 AC 208 ms
5,376 KB
testcase_15 AC 161 ms
5,376 KB
testcase_16 AC 176 ms
5,376 KB
testcase_17 AC 133 ms
5,376 KB
testcase_18 AC 108 ms
5,376 KB
testcase_19 AC 68 ms
5,376 KB
testcase_20 AC 247 ms
5,376 KB
testcase_21 AC 44 ms
5,376 KB
testcase_22 AC 138 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll powmod(ll a, ll b, ll MOD){
	if(b == 0) return 1;
	if(b & 1) {
		return a * powmod(a, b - 1, MOD) % MOD;
	} else {
		ll d = powmod(a, b / 2, MOD) % MOD;
		return d * d % MOD;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll a, b, c;
	cin >> a >> b >> c;

	ll q = a / c, r = a % c;

	ll ans = 0;
	for(ll i = 0; i < c; i++){
		ans += powmod(i, b, c);
		ans %= c;
	}

	ans *= q;
	ans %= c;

	rep(i, r+1){
		ans += powmod(q * c + i, b, c);
		ans %= c;
	}

	cout << ans << endl;
}
0