結果

問題 No.2249 GCDistance
ユーザー flygonflygon
提出日時 2023-03-18 15:12:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,294 ms / 5,000 ms
コード長 923 bytes
コンパイル時間 2,904 ms
コンパイル使用メモリ 249,716 KB
実行使用メモリ 135,132 KB
最終ジャッジ日時 2023-10-18 17:18:30
合計ジャッジ時間 19,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 971 ms
135,132 KB
testcase_01 AC 1,258 ms
135,132 KB
testcase_02 AC 1,289 ms
135,132 KB
testcase_03 AC 1,291 ms
135,132 KB
testcase_04 AC 1,108 ms
135,132 KB
testcase_05 AC 1,294 ms
135,132 KB
testcase_06 AC 1,263 ms
135,132 KB
testcase_07 AC 1,273 ms
135,132 KB
testcase_08 AC 1,011 ms
135,132 KB
testcase_09 AC 1,289 ms
135,132 KB
testcase_10 AC 1,231 ms
135,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false); cin.tie(nullptr);
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

#define rep(i,n) for(int i = 0; i < n; i++)

const long long MOD = 1000000007;

vector<long long> calc_totient(long long M){
    vector<long long> phi;
    rep(i,M+1){
        phi.push_back(i);
    }
    for (int i = 2; i <= M; i++){
        if (phi[i] == i){
            for (int j = i; j <= M; j+=i){
                phi[j] = phi[j] / i * (i-1);
            }
        }
    }
    return phi;
}

int main() {
    fast_io
    long long M = 10000000;
    vector<long long> phi = calc_totient(M);
    for(int i = 1; i <= M; i++){
        phi[i] += phi[i-1];
    }
    int t;
    cin >> t;
    rep(i, t){
        long long n;
        cin >> n;
        long long ans = 0;
        ans = -phi[n] + n*(n-1) + 1;
        cout << ans << endl;
    }
}
0