結果
| 問題 | 
                            No.1161 Many Powers
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-08-15 06:24:58 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 104 ms / 2,000 ms | 
| コード長 | 777 bytes | 
| コンパイル時間 | 3,986 ms | 
| コンパイル使用メモリ | 194,032 KB | 
| 最終ジャッジ日時 | 2025-01-13 01:05:15 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 23 | 
ソースコード
#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() {
	cin.tie(0);ios::sync_with_stdio(false);
	long long A,B,C; cin >> A >> B >> C;
	long long ans = 0;
	vector<long long> cnt(C+1,0);
	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.end(),0LL)%C)*(A/C);
	cout << ans%C << endl;
    return 0;
}