結果

問題 No.1022 Power Equation
ユーザー SSRSSSRS
提出日時 2020-04-10 23:04:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 167,328 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 04:15:06
合計ジャッジ時間 3,957 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
  vector<bool> power(40000);
  for (int i = 2; i < 40000; i++){
    power[i] = is_power(i);
  }
  for (int i = 0; i < T; i++){
    long long N;
    cin >> N;
    long long ans = N * N * 2 - N;
    bool two = false;
    for (int j = 2; j * j <= N; j++){
      //j: base
      if (power[j]){
        continue;
      }
      if (two){
        ans += N / 2 * 2;
      } else {
        int X = logfloor(j, N);
        if (X == 2){
          two = true;
        }
        long long A = 0;
        for (int k = 2; k <= X; k++){
          A += N / k * (k - 1) * 2;
        }
        ans += A;
      }
    }
    cout << ans << endl;
  }
}
0