Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
415 B
17
Indexable
Never
vector<vector<int>> solve(int n){
	if(n%2 == 1){
		return {{-1, -1}};
	}
	vector<vector<int>> ans;
	vector<vector<int>> temp;
	for(int i = 1; i < n/2; i++){
		int j = n - i;
		int val = i^j;
		val = 2*val;
		if(val == n){
			ans.push_back({i, j});
			temp.push_back({j, i});
		}
	}
	for(int i = temp.size() - 1; i >= 0; i--){
		ans.push_back(temp[i]);
	}
	if(ans.size() == 0){
		return {{-1, -1}};
	}
	return ans;
}
Leave a Comment