結果

問題 No.1161 Many Powers
ユーザー ningenMeningenMe
提出日時 2020-08-15 06:28:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 3,386 ms
コンパイル使用メモリ 212,900 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 23:39:57
合計ジャッジ時間 4,460 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 30 ms
6,948 KB
testcase_09 AC 35 ms
6,940 KB
testcase_10 AC 14 ms
6,944 KB
testcase_11 AC 25 ms
6,944 KB
testcase_12 AC 13 ms
6,944 KB
testcase_13 AC 41 ms
6,940 KB
testcase_14 AC 61 ms
6,944 KB
testcase_15 AC 51 ms
6,940 KB
testcase_16 AC 69 ms
6,944 KB
testcase_17 AC 46 ms
6,940 KB
testcase_18 AC 33 ms
6,940 KB
testcase_19 AC 20 ms
6,940 KB
testcase_20 AC 72 ms
6,940 KB
testcase_21 AC 19 ms
6,940 KB
testcase_22 AC 73 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

class ArbitraryMod{
public:
	//Pow_Mod O(log(n))
	inline static long long pow(long long x, long long n, long long mod) {
		long long res = 1;
		for (x %= mod; n > 0; n >>= 1, (x *= x) %= mod) if (n & 1) (res *= x) %= mod;
		return res;
	}
	//Inv_Mod O(log(mod))
	inline static long long inv(long long x, long long mod){
		return pow(x,mod-2,mod); 
	}
};

int main() {
	long long A,B,C;
	scanf("%lld%lld%lld",&A,&B,&C);
	long long ans = 0;
	array<long long,100001> cnt;
	for(long long i = 1; i <= C; ++i) {
		cnt[i] = ArbitraryMod::pow(i,B,C);
	}
	for(long long i = 1; i <= A%C; ++i) {
		ans += cnt[i];
	}
	ans += (accumulate(cnt.begin(),cnt.begin()+C,0LL)%C)*(A/C);
	printf("%lld\n",ans%C);
    return 0;
}
0