結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 15:47:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 800 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 193,460 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-15 15:47:16
合計ジャッジ時間 4,381 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     freopen("mod.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:16:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     freopen("mod.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const int N = 2e5 + 1;
int n;
ll a[N];

ll cnt[N << 1];
ll ans;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    freopen("mod.in", "r", stdin);
    freopen("mod.out", "w", stdout);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        cnt[a[i]] ++;
        ans += a[i] * n;
    }

    for(int i = 1; i < (N << 1); i ++){
        cnt[i] += cnt[i - 1];
    }

    for(int mod = 1; mod < N; mod ++){
        for(int k = 0; k * mod < N; k ++){
            ans -= (cnt[(k + 1) * mod - 1] - (k * mod - 1 >= 0 ? cnt[k * mod - 1] : 0)) * (cnt[mod] - cnt[mod - 1]) * (mod * k);
        }
    }

    cout << ans;

    return 0;
}

/***

3
1 5 3

8
8 8 8 8 8 8 8 8

***/

0