結果

問題 No.1022 Power Equation
ユーザー SSRSSSRS
提出日時 2020-04-10 23:00:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 164,296 KB
実行使用メモリ 11,384 KB
最終ジャッジ日時 2023-10-14 04:04:23
合計ジャッジ時間 7,770 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int logfloor(int a, long long b){
  //floor(log_a(b))
  if (a > b){
    return 0;
  } else {
    int res = 1;
    long long A = a;
    while (A * a <= b){
      A *= a;
      res++;
    }
    return res;
  }
}
bool is_power(long long a){
  //aがべきならtrue
  int X = logfloor(2, a);
  X++;
  for (int i = 2; i <= X; i++){
    //aのi乗根
    long long Y = pow(a, (double) 1 / i);
    long long Z = pow(Y, i);
    if (Z == a){
      return true;
    }
    Y++;
    Z = pow(Y, i);
    if (Z == a){
      return true;
    }
  }
  return false;
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    long long N;
    cin >> N;
    long long ans = N * N * 2 - N;
    for (int j = 2; j * j <= N; j++){
      //j: base
      if (is_power(j)){
        continue;
      }
      int X = logfloor(j, N);
      long long A = 0;
      for (int k = 2; k <= X; k++){
        A += N / k * (k - 1) * 2;
      }
      ans += A;
    }
    cout << ans << endl;
  }
}
0