結果
| 問題 |
No.3102 floor sqrt xor
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-04-14 13:04:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 760 bytes |
| コンパイル時間 | 494 ms |
| コンパイル使用メモリ | 58,460 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-14 13:04:42 |
| 合計ジャッジ時間 | 2,082 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d", &tn);
| ~~~~~^~~~~~~~~~~
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
ソースコード
/* -*- 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;
}
tnakao0123