結果

問題 No.2249 GCDistance
ユーザー simansiman
提出日時 2023-04-25 14:46:43
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 686 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 125,440 KB
実行使用メモリ 91,904 KB
最終ジャッジ日時 2024-04-26 20:03:36
合計ジャッジ時間 13,721 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;
typedef long long ll;

ll euler_phi(ll n) {
  ll ret = n;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ret -= ret / i;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if(n > 1) {
    ret -= ret / n;
  }
  return ret;
}

ll sum[10000010];

int main() {
  int T;
  cin >> T;

  memset(sum, 0, sizeof(sum));
  for (ll n = 2; n <= 10000000; ++n) {
    sum[n] = sum[n - 1] + euler_phi(n);
  }

  for (int i = 0; i < T; ++i) {
    ll N;
    cin >> N;

    ll all = (N - 1) * N / 2;
    ll ans = all + (all - sum[N]);
    cout << ans << endl;
  }

  return 0;
}

0