結果

問題 No.2249 GCDistance
コンテスト
ユーザー Rumain831
提出日時 2026-08-08 11:20:45
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 506 ms / 5,000 ms
+ 805µs
コード長 789 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,243 ms
コンパイル使用メモリ 174,644 KB
実行使用メモリ 159,744 KB
最終ジャッジ日時 2026-08-08 11:21:05
合計ジャッジ時間 10,978 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<ll> Phi(int n){
  vector<ll> ans(n+1);
  for(int i=1; i<=n; i++) ans[i]=i;
  for(int p=2; p<=n; p++)if(ans[p]==p){
    for(int x=p; x<=n; x+=p){
      ans[x]=ans[x]/p*(p-1);
    }
  }
  return ans;
}

int main(void){
  vector<ll> phi=Phi(1e7+1), sum=phi;
  sum[1]=0;
  for(int i=2; i<=1e7; i++) sum[i]+=sum[i-1];
  // for(int i=1; i<=10; i++) cout << phi[i] << ' '; cout << endl;
  // for(int i=1; i<=10; i++) cout << sum[i] << ' '; cout << endl;
  int t; cin >> t;
  while(t--){
    ll n; cin >> n;
    ll dis=sum[n], non=n*(n-1)/2-dis;
    //cout << n << ' ' << dis << ' ' << non << endl;
    ll ans=dis+non*2;
    cout << ans << '\n';
  }
  return 0; 
}
0