結果

問題 No.2249 GCDistance
ユーザー kuronikuroni
提出日時 2023-03-22 05:02:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 518 ms / 5,000 ms
コード長 727 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 169,728 KB
実行使用メモリ 159,408 KB
最終ジャッジ日時 2023-10-18 18:48:08
合計ジャッジ時間 9,384 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 456 ms
159,408 KB
testcase_01 AC 514 ms
159,408 KB
testcase_02 AC 518 ms
159,408 KB
testcase_03 AC 515 ms
159,408 KB
testcase_04 AC 485 ms
159,408 KB
testcase_05 AC 512 ms
159,408 KB
testcase_06 AC 501 ms
159,408 KB
testcase_07 AC 496 ms
159,408 KB
testcase_08 AC 458 ms
159,408 KB
testcase_09 AC 503 ms
159,408 KB
testcase_10 AC 508 ms
159,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MX = 1E7 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> pr(MX), phi(MX);
    phi[1] = 1;
    vector<long long> ans(MX);
    for (int i = 2; i < MX; i++) {
        if (pr[i] == 0) {
            pr[i] = i;
            for (int j = i; j <= (MX - 1) / i; j++) {
                pr[i * j] = i;
            }
        }
        int t = i, p = pr[i];
        while (t % p == 0) {
            t /= p;
        }
        phi[i] = phi[t] * (i / t) / p * (p - 1);
        ans[i] = ans[i - 1] + phi[i] + (i - 1 - phi[i]) * 2;
    }
    int t; cin >> t;
    while (t--) {
        int u; cin >> u;
        cout << ans[u] << '\n';
    }
}
0