結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 16:35:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 3,153 ms
コード長 1,180 bytes
コンパイル時間 3,200 ms
コンパイル使用メモリ 276,492 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2025-08-15 16:35:08
合計ジャッジ時間 5,570 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   48 |   for(register int i = 1; i <= 2e5; i++) {
      |                    ^
main.cpp:50:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   50 |       for(register int j = i; j <= 2e5; j += i) {
      |                        ^

ソースコード

diff #

#include<bits/stdc++.h>

#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")

using namespace std;
using ll = long long;

char buf[1 << 20], *p1, *p2;
#define gc()                                                               \
  (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) \
       ? EOF                                                               \
       : *p1++)

inline void read(int &s) {
  for(char ch; ch = gc();) {
    if(isdigit(ch)) {
      s = s * 10 + ch - '0';
      break;
    }
  }
  for(char ch; ch = gc();) {
    if(isdigit(ch)) {
      s = s * 10 + ch - '0';
    }else{
      break;
    }
  }
}

const int MAXN = 2e5 + 25;

int n;
ll ans;
int a[MAXN];
ll c[MAXN];
int cnt[MAXN];

int main(){
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read(n);
  for(int i = 1; i <= n; i++) {
    read(a[i]);
    ans += a[i];
    cnt[a[i]]++;
  }
  ans *= n;
  for(register int i = 1; i <= 2e5; i++) {
    if(cnt[i] != 0){
      for(register int j = i; j <= 2e5; j += i) {
        c[j] += 1LL * cnt[i] * i;
      }
      c[i] += c[i - 1];
      ans -= 1LL * cnt[i] * c[i];
    }else c[i] += c[i - 1];
  }
  cout << ans;
  return 0;
}
0