Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 15:58:05
2016-05-28 15:54:52
2016-05-28 15:50:38
2016-05-28 15:49:47
Task:Fixed points
Sender:Game of Nolife
Submission time:2016-05-28 15:58:05
Status:READY
Result:WRONG ANSWER

Show test data

Code

#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef unsigned long long ll;
typedef long double ld;

ll go(ll x, ll a, ll b, ll i) {
	if (i == 64) {
		if (((a*x)^b) == x) {
			return x;
		} else {
			return 0;
		}
	}
	if ((((a*x)^b)&((1<<i)-1)) == (x&((1<<i)-1))) {
		ll y = go(x, a, b, i + 1);
		if (y > 0) {
			return y;
		} else {
			y = go(x + (1 << i), a, b, i + 1);
			if (y > 0) {
				return y;
			} else {
				return 0;
			}
		}
	}
	return 0;
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	for (int tc = 0; tc < t; tc++) {
		ll a, b;
		cin >> a >> b;
		if (b == 0) {
			cout << "0\n";
		} else {
			ll x = go(0, a, b, 0);
			if (x == 0) {
				cout << "-\n";
			} else {
				cout << x << "\n";
			}
		}
	}
}