結果
| 問題 |
No.1161 Many Powers
|
| ユーザー |
|
| 提出日時 | 2025-07-07 13:26:08 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 71 ms / 2,000 ms |
| コード長 | 501 bytes |
| コンパイル時間 | 3,122 ms |
| コンパイル使用メモリ | 275,520 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-07-07 13:26:13 |
| 合計ジャッジ時間 | 5,023 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll mod_pow(ll a,ll n,ll mod){
ll ret=1%mod;
a=a%mod;
while(n){
if(n&1)ret=ret*a%mod;
a=a*a%mod;
n>>=1;
}
return ret;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
ll A,B,C;cin>>A>>B>>C;
ll ans=0;
for(ll i=1;i<=min(A,C-1);++i){
// 1<=i+kC<=A
// 1-i<=kC<=A-i
// (1-i)/C<=k<=(A-i)/C
ll cnt=(A-i)/C+1;
cnt%=C;
ans+=mod_pow(i,B,C)*cnt%C;
if(C<=ans)ans-=C;
}
cout<<ans<<endl;
}