CSES - HIIT Open 2016 - Results
Submission details
Task:Fixed points
Sender:Game of Nolife
Submission time:2016-05-28 15:58:05 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.93 sdetails

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";
			}
		}
	}
}

Test details

Test 1

Verdict:

input
100000
12865169357617740396 294321893...

correct output
5903494652862419412
-
13008184152928659765
9415006529485574473
16201136572240455608
...

user output
-
-
-
-
-
...