結果
| 問題 | No.1161 Many Powers |
| ユーザー |
|
| 提出日時 | 2020-08-15 06:29:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 2,000 ms |
| コード長 | 826 bytes |
| 記録 | |
| コンパイル時間 | 3,203 ms |
| コンパイル使用メモリ | 217,968 KB |
| 最終ジャッジ日時 | 2025-01-13 01:06:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%lld%lld%lld",&A,&B,&C);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
class Mod{
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] = Mod::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;
}