結果
問題 | No.1218 Something Like a Theorem |
ユーザー |
![]() |
提出日時 | 2020-09-13 20:23:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 935 bytes |
コンパイル時間 | 1,839 ms |
コンパイル使用メモリ | 194,012 KB |
最終ジャッジ日時 | 2025-01-14 14:34:15 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 |
ソースコード
#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; }