結果
| 問題 |
No.3102 floor sqrt xor
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 22:28:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,266 bytes |
| コンパイル時間 | 2,222 ms |
| コンパイル使用メモリ | 194,900 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-11 22:28:52 |
| 合計ジャッジ時間 | 3,375 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
void Solve(){
ll N;
cin>>N;
if(N==0){
cout<<0<<"\n";
return;
}
int B=-1;
for(int i=60;i>=0;i--){
if(N>>i&1){
B=i;
break;
}
}
assert(B!=-1);
ll L=0,R=0;
for(int i=0;i<=B/2;i++){
R^=1LL<<i;
}
for(int i=B/2+1;i<=B;i++){
if(N>>i&1){
L^=1LL<<i;
R^=1LL<<i;
}
}
auto find_sq=[](ll x)-> ll {
ll l=0,r=(ll)sqrt(x)+10;
while(r-l>1){
ll mid=(l+r)/2;
if(mid*mid<=x)l=mid;
else r=mid;
}
return l;
};
ll sl=find_sq(L),sr=find_sq(R);
for(ll m=sl;m<=sr+1;m++){
if(m*m<=(N^m)&&(N^m)<(m+1)*(m+1)){
cout<<(N^m)<<"\n";
return;
}
}
cout<<-1<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin>>T;
while(T--){
Solve();
}
}