結果

問題 No.2249 GCDistance
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-09 12:53:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,274 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 7,937 ms
コンパイル使用メモリ 195,172 KB
実行使用メモリ 159,608 KB
最終ジャッジ日時 2024-04-09 12:56:05
合計ジャッジ時間 27,706 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,171 ms
159,464 KB
testcase_01 AC 1,210 ms
159,496 KB
testcase_02 AC 1,198 ms
159,380 KB
testcase_03 AC 1,217 ms
159,444 KB
testcase_04 AC 1,119 ms
159,560 KB
testcase_05 AC 1,245 ms
159,464 KB
testcase_06 AC 1,261 ms
159,608 KB
testcase_07 AC 1,274 ms
159,504 KB
testcase_08 AC 1,216 ms
159,436 KB
testcase_09 AC 1,250 ms
159,472 KB
testcase_10 AC 1,270 ms
159,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    const int M = 1e7 + 1;
    vector<long long> dp(M + 1);
    iota(dp.begin(), dp.end(), 0);
    dp[1] = 1;
    for (int i = 1; i <= M; i++) {
        for (int j = 2 * i; j <= M; j += i) {
            dp[j] -= dp[i];
        }
    }
    vector<long long> cum(M + 1);
    for (int i = 1; i <= M; i++) {
        cum[i] = cum[i - 1] + dp[i];
    }
    int t;
    cin >> t;
    for (; t--;) {
        int n;
        cin >> n;
        cout << (long long)n * (n - 1) - cum[n] + 1 << "\n";
    }
}
0