You are given three non-negative integers b , c , and d . Please find a non-negative…
- User
You are given three non-negative integers b , c , and d .
Please find a non-negative integer a∈[0,261] such that (a|b)−(a&c)=d , where | and & denote the bitwise OR operation and the bitwise AND operation, respectively.
If such an a exists, print its value. If there is no solution, print a single integer −1 . If there are multiple solutions, print any of them.
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105 ). The description of the test cases follows.
The only line of each test case contains three positive integers b , c , and d (0≤b,c,d≤1018 ).
Output For each test case, output the value of a , or −1 if there is no solution. Please note that a must be non-negative and cannot exceed 261 .
Example InputCopy 3 2 2 2 4 2 6 10 2 14 OutputCopy 0 -1 12 Note In the first test case, (0|2)−(0&2)=2−0=2 . So, a=0 is a correct answer.
In the second test case, no value of a satisfies the equation.
In the third test case, (12|10)−(12&2)=14−0=14 . So, a=12 is a correct answer./**
- author: Aykhan_2009
- created: 09.29.2024 1:38 **/ #include <bits/stdc++.h>
using namespace std;
#define ll long long #define ld long double #define endl '\n' #define pb push_back #define speedyboy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) x.begin() , x.end() #define F first #define S second #define pll pair<ll , ll> #define YES cout << "YES" << endl; #define NO cout << "NO" << endl;
ll i , j , k , ans; const ll sz = 5e5 + 5 , INF = 1e9 + 7 , MOD = 1e9 + 7; ll a[sz];
void solve(){ ll b , bi , c , ci , d , di; cin >> b >> c >> d; ll res = 0; for(i = 1 ; i <= 61 ; i++){ bi = (b >> i) % 2; ci = (c >> i) % 2; di = (d >> i) % 2; if((bi == 1 && ci == 0 && di == 0) || (bi == 0 && ci == 1 && di == 1)){ cout << -1 << endl; return; } if(bi == 1 && ci == 1 && di == 0){ res |= (1 << i); } if(bi == 0 && ci == 0 && di == 1){ res |= (1 << i); } } cout << res << endl; }
signed main(){ speedyboy; //open; ll t = 1; cin >> t; while(t--){ solve(); } } Ne için benim kodum yanlış?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.