結果

問題 No.1218 Something Like a Theorem
ユーザー kyo1kyo1
提出日時 2020-09-13 20:23:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 198,960 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 23:55:51
合計ジャッジ時間 2,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

int sqrt(int x, int n) {
  int lo = 0, hi = x;
  while (lo <= hi) {
    int mi = (lo + hi) / 2;
    if (pow(mi, n) == x) {
      return mi;
    } else if (pow(mi, n) < x) {
      lo = mi + 1;
    } else {
      hi = mi - 1;
    }
  }
  return -1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, z;
  cin >> n >> z;
  int zn = pow(z, n);
  for (int i = 1; i < z + 1; i++) {
    if (zn - pow(i, n) < 1) continue;
    int j = sqrt(zn - pow(i, n), n);
    if (j != -1) {
      cout << "Yes" << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}
0