結果
問題 | No.2260 Adic Sum |
ユーザー |
|
提出日時 | 2023-04-07 21:48:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 626 ms / 2,000 ms |
コード長 | 894 bytes |
コンパイル時間 | 1,076 ms |
コンパイル使用メモリ | 85,764 KB |
最終ジャッジ日時 | 2025-02-12 01:04:04 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<map> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll P; cin>>N>>P; vector<ll>A(N); rep(i,N)cin>>A[i]; vector<ll>C(30); ll q=P; rep(i,30){ if(q>1e9)break; map<ll,ll>mp; rep(j,N){ mp[A[j]%q]++; } for(auto[x,y]:mp)C[i]+=y*(y-1)/2; q*=P; } rep(i,29)C[i]-=C[i+1]; ll ans=0; rep(i,30)ans+=(i+1)*C[i]; cout<<ans<<"\n"; }