結果
問題 |
No.2046 Ans Mod? Mod Ans!
|
ユーザー |
👑 ![]() |
提出日時 | 2022-08-19 21:28:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 4,000 ms |
コード長 | 756 bytes |
コンパイル時間 | 873 ms |
コンパイル使用メモリ | 72,536 KB |
最終ジャッジ日時 | 2025-01-31 00:38:41 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
//https://yukicoder.me/problems/no/1233 #include<iostream> #include<algorithm> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N; int A[200000]; LL C[200001]={}; LL SC[200001]={}; LL SCC[200001]={}; int main(){ cin>>N; rep(i,N) cin>>A[i]; sort(A,A+N); rep(i,N) C[A[i]]++; rep(i,200000) SC[i+1]=SC[i]+C[i+1]; rep(i,200001) SCC[i]=i*C[i]; rep(i,200000) SCC[i+1]+=SCC[i]; LL ans=0; for(int i=1; i<=200000; i++){ for(int j=0; j<=200000; j+=i){ LL tmp = SCC[min(j+i-1,200000)] - SCC[j]; tmp -= (SC[min(j+i-1,200000)] - SC[j]) * j; tmp *= C[i]; ans += tmp; } } LL ans2=0; rep(i,N) ans2+=(LL)A[i]*(N-1-i); ans = ans2*2-ans; cout<<ans<<endl; return 0; }