結果

問題 No.1022 Power Equation
ユーザー risujirohrisujiroh
提出日時 2020-04-10 22:00:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 200,604 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 00:31:04
合計ジャッジ時間 2,995 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 34 ms
4,348 KB
testcase_05 AC 47 ms
4,348 KB
testcase_06 AC 46 ms
4,352 KB
testcase_07 AC 45 ms
4,348 KB
testcase_08 AC 24 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    long long n;
    cin >> n;
    long long m = 1;
    while ((m + 1) * (m + 1) <= n) {
      ++m;
    }
    long long res = n * n, cnt = n - m;
    vector<bool> b(m + 1);
    for (long long k = 2; k <= m; ++k) {
      if (b[k]) {
        continue;
      }
      DEBUG(k);
      long long l = 0;
      for (auto i = k; i <= n; i *= k) {
        if (i <= m) {
          b[i] = true;
        } else {
          --cnt;
        }
        ++l;
      }
      for (int j = 1; j <= l; ++j) {
        for (int i = 1; i <= j; ++i) {
          if (i == j) {
            res += n;
          } else {
            res += 2 * (n / (j / gcd(i, j)));
          }
        }
      }
    }
    res += cnt * n;
    cout << res << '\n';
  }
}
0