結果

問題 No.1022 Power Equation
ユーザー MayimgMayimg
提出日時 2020-07-23 20:06:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 205,828 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 23:24:55
合計ジャッジ時間 3,101 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 17 ms
4,376 KB
testcase_04 AC 36 ms
4,380 KB
testcase_05 AC 38 ms
4,376 KB
testcase_06 AC 37 ms
4,376 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 35 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
constexpr long long N = 100000;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  auto solve = [&] () -> long long {
    long long n;
    cin >> n;
    long long one = max(0LL, n - N);
    vector<bool> ok(N + 10, true);
    vector<vector<long long>> p(35, vector<long long>(35));
    long long ans = n * n;
    for (long long x = 2; x <= min(n, N); x++) if (ok[x]) {
      int cnt = 0;
      long long y = x;
      while (y <= n) {
        cnt++;
        if (y <= N) ok[y] = false;
        else one--;
        y *= x;
      }
      for (int i = 1; i <= cnt; i++) for (int j = 1; j <= cnt; j++) {
        p[i][j]++;
      }
    }
    p[1][1] += one;
    for (int i = 1; i < 35; i++) for (int j = 1; j < 35; j++) {
      int g = __gcd(i, j);
      int k = max(i, j) / g;
      ans += p[i][j] * (n / k);
    }
    return ans;
  };
  int t;
  cin >> t;
  while (t--) cout << solve() << '\n';
  return 0;
}
0