結果

問題 No.2249 GCDistance
ユーザー simansiman
提出日時 2023-04-25 15:18:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 984 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 126,592 KB
実行使用メモリ 159,784 KB
最終ジャッジ日時 2024-04-26 20:30:13
合計ジャッジ時間 12,757 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 532 ms
159,732 KB
testcase_01 AC 984 ms
159,680 KB
testcase_02 AC 908 ms
159,616 KB
testcase_03 AC 897 ms
159,624 KB
testcase_04 AC 664 ms
159,744 KB
testcase_05 AC 911 ms
159,616 KB
testcase_06 AC 908 ms
159,744 KB
testcase_07 AC 913 ms
159,616 KB
testcase_08 AC 543 ms
159,744 KB
testcase_09 AC 893 ms
159,684 KB
testcase_10 AC 875 ms
159,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
typedef long long ll;

const ll MAX_N = 10000000;
ll table[10000010];
ll ans[MAX_N + 10];

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

  memset(table, 0, sizeof(table));
  for (ll n = 1; n <= MAX_N; ++n) {
    table[n] = n;
  }
  for (ll n = 2; n <= MAX_N; ++n) {
    if (table[n] == n) {
      for (ll m = n; m <= MAX_N; m += n) {
        table[m] = table[m] / n * (n - 1);
      }
    }
  }

  table[1] = 1;
  memset(ans, 0, sizeof(ans));
  for (ll n = 1; n <= MAX_N; ++n) {
    ans[n + 1] = ans[n] + 2 * n - table[n + 1];
  }

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

    cout << ans[N] << endl;
  }

  return 0;
}
0