結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 15:53:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 3,153 ms
コード長 2,054 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 162,340 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2025-08-15 15:53:27
合計ジャッジ時間 4,022 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for (__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for (; __c > 31 && __c < 127 && __c != ' ' && __c != '\n' && __c != '\r'; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0', x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

const int MAXN = 2e5 + 10, INF = 2e9;

int n, a[MAXN];
ll s[MAXN << 1];

int main() {
  //freopen("mod.in", "r", stdin);
  //freopen("mod.out", "w", stdout);
  gi(n);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    gi(a[i]);
    s[a[i]]++;
    ans += 1ll * a[i] * n;
  }
  for (int i = 1; i < MAXN << 1; i++) {
    s[i] += s[i - 1];
  }
  for (int i = 1; i < MAXN; i++) {
    ll x = s[i] - s[i - 1];
    for (int k = 0; i * k < MAXN; k++) {
      ll r = s[(k + 1) * i - 1];
      if (i * k > 0) r -= s[i * k - 1];
      ans -= r * x * i * k;
    }
  }
  print(ans);
  return 0;
}
0