Hello coders, today we are going to solve AND Plus OR Codechef Solution|Problem Code: ANDOR.

Problem
Given an integer x, find two non-negative integers a and b such that (a∧b)+(a∨b)=x(a∧b)+(a∨b)=x, where ∧ is the bitwise AND operation and ∨ is the bitwise OR operation.
Input
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains a single integer x.
Output
If there is no valid pair (a,b), print a single line containing the integer −1. Otherwise, print a single line containing two space-separated integers aa and bb.
If there are multiple solutions, you may print any one of them.
Constraints
- 1≤T≤1051≤T≤105
- 1≤x≤10181≤x≤1018
Subtasks
Subtask #1 (30 points):
- 1≤T≤2001≤T≤200
- 1≤x≤2001≤x≤200
Subtask #2 (70 points): original constraints
Sample Input 1
2
1
8
Sample Output 1
0 1
5 3
AND Plus OR CodeChef Solution in JAVA
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int tc = 0; tc < T; ++tc) { long x = sc.nextLong(); System.out.println(solve(x)); } sc.close(); } static String solve(long x) { return String.format("0 %d", x); } }
Disclaimer: The above Problem (AND Plus OR) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.