結果
問題 | No.3102 floor sqrt xor |
ユーザー |
![]() |
提出日時 | 2025-01-13 23:15:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 644 bytes |
コンパイル時間 | 2,069 ms |
コンパイル使用メモリ | 191,636 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-13 23:24:41 |
合計ジャッジ時間 | 3,663 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; // [floor_sqrt(N)] // 0 <= N <= 9e18 long long floor_sqrt(long long N) { long long ub = 3'000'000'001; long long lb = 0; while (ub - lb > 1) { long long t = (ub + lb) / 2; if (t * t <= N) lb = t; else ub = t; } return lb; } typedef long long ll; void solve() { ll n; cin >> n; ll lb = floor_sqrt((n >> 30) << 30) - 5; ll ub = floor_sqrt(((n >> 30) + 1) << 30) + 5; for (ll x=lb; x<ub; x++) { if (x < 0) continue; if (x*x <= (n^x) && (n^x) < (x+1)*(x+1)) { cout << (n^x) << '\n'; return; } } cout << -1 << '\n'; } int main() { int t; cin >> t; while(t--) solve(); }