結果

問題 No.2249 GCDistance
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-05 00:06:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,776 ms / 5,000 ms
コード長 853 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 106,204 KB
実行使用メモリ 159,688 KB
最終ジャッジ日時 2024-05-02 03:12:45
合計ジャッジ時間 22,423 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,250 ms
159,688 KB
testcase_01 AC 1,653 ms
159,684 KB
testcase_02 AC 1,608 ms
159,556 KB
testcase_03 AC 1,642 ms
159,560 KB
testcase_04 AC 1,393 ms
159,616 KB
testcase_05 AC 1,655 ms
159,560 KB
testcase_06 AC 1,649 ms
159,556 KB
testcase_07 AC 1,776 ms
159,688 KB
testcase_08 AC 1,262 ms
159,684 KB
testcase_09 AC 1,647 ms
159,556 KB
testcase_10 AC 1,628 ms
159,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

const ll sz=1e7;
ll phi[sz+1], S[sz+1];

void init(){
    phi[0] = 0;
    for (int i=2; i<=sz; i++) phi[i] = i;
    for (int i=2; i<=sz; i++){
        if (phi[i] == i){
            for (int j=i; j<=sz; j+=i){
                phi[j] /= i;
                phi[j] *= (i-1);
            }
        }
    }
    S[0] = 0;
    for (int i=1; i<=sz; i++){
        S[i] = S[i-1] + phi[i];
    }
}

int main(){

    init();
    ll T, N, M, K;
    cin >> T;

    while(T){
        T--;
        cin >> N;
        M = N*(N-1)/2;
        K = S[N];
        cout << K + (M-K)*2 << endl;
    }

    return 0;
}
0