結果

問題 No.3102 floor sqrt xor
ユーザー GOTKAKO
提出日時 2025-04-11 22:37:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,463 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 195,312 KB
実行使用メモリ 15,944 KB
最終ジャッジ日時 2025-04-11 22:37:36
合計ジャッジ時間 8,036 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 WA * 6 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    auto Sqrt = [&](long long x) -> long long {
        if(x == 0) return 0;
        if(x <= 3) return 1;
        long long s = sqrt(x);

        if(s*s == x) return s;
        if((s-1)*(s-1) == x) return s-1;
        if((s+1)*(s+1) == x) return s+1;
        
        if(s*s >= x) return s-1;
        if((s+1)*(s+1) >= x) return s;
        return s+1;
    };

    int T; cin >> T;
    while(T--){
        //N++;
        long long N; cin >> N;
        long long answer = -1;
        for(int i=0; i<=100; i++) if((Sqrt(i)^i) == N){answer = i; break;}
        if(answer != -1){cout << answer << "\n"; continue;}
        
        long long sN = Sqrt(N),ssN = Sqrt(sN)*100;
        for(long long i=N-sN-ssN; i<=N-sN+ssN; i++){
            if(i < 0) continue;
            if((Sqrt(i)^i) == N){answer = i; break;}
        }
        if(answer == -1) for(long long i=N+sN-ssN; i<=N+sN+ssN; i++){
            if(i < 0) continue;
            if((Sqrt(i)^i) == N){answer = i; break;}
        }
        
        if(answer == -1 && false){
            for(int i=0; i<=N*2; i++){
                if((Sqrt(i)^i) == N){
                    cout << "Wrong" << endl;
                    cout << N << " " << i << endl;
                    return 0;
                }
            }
            cout << N << endl;
        }
        cout << answer << "\n";
    }
}
0