結果

問題 No.2249 GCDistance
ユーザー ei1333333ei1333333
提出日時 2023-03-17 21:56:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 784 ms / 5,000 ms
コード長 801 bytes
コンパイル時間 3,088 ms
コンパイル使用メモリ 204,176 KB
実行使用メモリ 120,216 KB
最終ジャッジ日時 2023-10-18 14:32:47
合計ジャッジ時間 12,727 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 419 ms
120,128 KB
testcase_01 AC 784 ms
120,128 KB
testcase_02 AC 778 ms
120,216 KB
testcase_03 AC 773 ms
120,216 KB
testcase_04 AC 544 ms
120,216 KB
testcase_05 AC 774 ms
120,216 KB
testcase_06 AC 772 ms
120,216 KB
testcase_07 AC 766 ms
120,216 KB
testcase_08 AC 423 ms
120,216 KB
testcase_09 AC 777 ms
120,216 KB
testcase_10 AC 701 ms
120,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;

#line 1 "math/number-theory/euler-phi-table.hpp"
/**
 * @brief Euler’s Phi Table(オイラーのφ関数テーブル)
 * @docs docs/euler-phi-table.md
 */
vector< int > euler_phi_table(int n) {
  vector< int > euler(n + 1);
  for(int i = 0; i <= n; i++) {
    euler[i] = i;
  }
  for(int i = 2; i <= n; i++) {
    if(euler[i] == i) {
      for(int j = i; j <= n; j += i) {
        euler[j] = euler[j] / i * (i - 1);
      }
    }
  }
  return euler;
}

int main() {
  auto X = euler_phi_table(1e7);
  vector< int64 > sum(1e7+1);
  for(int i = 1; i < sum.size(); i++) {
    if(i>0)sum[i]+=sum[i-1];
    sum[i]+=X[i];
  }
  int T;
  cin >> T;
  while(T--) {
    int N;
    cin >> N;
    cout << 1ll*N*(N-1)-sum[N]+1<<endl;
  }
}
0