結果

問題 No.3102 floor sqrt xor
ユーザー t98slider
提出日時 2025-04-11 22:23:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 196,344 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-11 22:24:01
合計ジャッジ時間 20,517 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    auto f = [&](ll v, ll n){
        for(ll i = v; i <= v + 500000; i++){
            if((i ^ (ll)(sqrtl(i))) == n) return i;
        }
        return -1ll;
    };
    while(T--){
        ll n;
        cin >> n;
        if(n == 0){
            cout << "0\n";
            continue;
        }
        ll k = __lg(n);
        ll sqk = sqrtl(k);
        ll S = (1ll << (__lg(sqk) + 1) - 1);
        ll ans = f(k, n);
        if(ans != -1){
            cout << ans << '\n';
            continue;
        }
        k = n & (~S);
        ans = f(k, n);
        if(ans != -1){
            cout << ans << '\n';
            continue;
        }
        sqk = sqrtl(k);
        S = (1ll << (__lg(sqk) + 1) - 1);
        k = n & (~S);
        ans = f(k, n);
        if(ans != -1){
            cout << ans << '\n';
            continue;
        }
        S = (1ll << (__lg(sqk) + 2) - 1);
        k = n & (~S);
        ans = f(k, n);
        cout << ans << '\n';
    }
}
0