結果

問題 No.2249 GCDistance
ユーザー merom686merom686
提出日時 2023-03-18 01:36:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 434 ms / 5,000 ms
コード長 598 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 201,104 KB
実行使用メモリ 120,828 KB
最終ジャッジ日時 2023-10-18 16:52:03
合計ジャッジ時間 8,508 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 369 ms
120,820 KB
testcase_01 AC 424 ms
120,828 KB
testcase_02 AC 422 ms
120,828 KB
testcase_03 AC 422 ms
120,828 KB
testcase_04 AC 387 ms
120,828 KB
testcase_05 AC 434 ms
120,828 KB
testcase_06 AC 420 ms
120,828 KB
testcase_07 AC 421 ms
120,828 KB
testcase_08 AC 373 ms
120,828 KB
testcase_09 AC 433 ms
120,828 KB
testcase_10 AC 423 ms
120,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int M = 1e7;
int a[M + 1];
ll s[M + 1];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;

    for (int i = 2; i <= M; i++) {
        a[i] = i;
    }
    for (int i = 2; i <= M; i++) {
        if (i == a[i]) {
            for (int j = i; j <= M; j += i) {
                a[j] = a[j] / i * (i - 1);
            }
        }
        s[i] = s[i - 1] + (i - 1) * 2 - a[i];
    }

    while (t--) {
        int n;
        cin >> n;

        cout << s[n] << '\n';
    }

    return 0;
}
0