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