結果

問題 No.3102 floor sqrt xor
コンテスト
ユーザー tnakao0123
提出日時 2025-04-14 13:04:39
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 760 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 247 ms
コンパイル使用メモリ 71,664 KB
実行使用メモリ 7,216 KB
最終ジャッジ日時 2026-07-08 20:45:34
合計ジャッジ時間 1,818 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3102.cc:  No.3102 floor sqrt xor - yukicoder
 */

#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

/* constant */

/* typedef */

using ll = long long;

/* global variables */

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    ll n;
    scanf("%lld", &n);

    if (n == 0) { puts("0"); continue; }
    if (n == 1) { puts("-1"); continue; }

    ll x0 = (n >> 30) << 30, x1 = ((n >> 30) + 1) << 30;
    int s0 = sqrt(0.5 + x0), s1 = sqrt(0.5 + x1);

    ll k = -1;
    for (int s = s0; s <= s1; s++) {
      ll sk = n ^ s;
      if (sk >= (ll)s * s && sk < (ll)(s + 1) * (s + 1)) {
	k = sk; break;
      }
    }

    printf("%lld\n", k);
  }

  return 0;
}
0