結果

問題 No.2249 GCDistance
ユーザー Shlok Goyal
提出日時 2025-06-27 23:01:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,519 ms / 5,000 ms
コード長 613 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 195,640 KB
実行使用メモリ 159,516 KB
最終ジャッジ日時 2025-06-27 23:02:49
合計ジャッジ時間 20,039 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    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