結果

問題 No.2249 GCDistance
ユーザー GiriGiri
提出日時 2023-07-28 22:03:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,236 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 194,376 KB
実行使用メモリ 81,792 KB
最終ジャッジ日時 2024-04-16 06:00:08
合計ジャッジ時間 18,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,148 ms
81,792 KB
testcase_01 AC 1,207 ms
81,564 KB
testcase_02 AC 1,215 ms
81,664 KB
testcase_03 AC 1,208 ms
81,620 KB
testcase_04 AC 1,153 ms
81,592 KB
testcase_05 AC 1,203 ms
81,720 KB
testcase_06 AC 1,213 ms
81,664 KB
testcase_07 AC 1,220 ms
81,496 KB
testcase_08 AC 1,161 ms
81,440 KB
testcase_09 AC 1,236 ms
81,684 KB
testcase_10 AC 1,214 ms
81,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i, m, n) for(ll i = m; i < n; ++i)

const ll MAXN = 10000001;
ll f[MAXN];

void Euler_Totient() {
    rep(i, 0, MAXN) f[i] = i;
        rep(i, 2, MAXN)
            if(f[i] == i)
                for(ll j = i; j <= MAXN - 1; j += i) f[j] = f[j] / i * (i - 1);
}

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

    Euler_Totient();
    rep(i, 1, MAXN) f[i] += f[i - 1];
    ll T; cin >> T;
    while(T--) {
        ll N; cin >> N;
        cout << N * (N - 1) - f[N] + 1<< "\n";
    }
    return 0;
}
0