AND Plus OR Codechef Solution

Hello Programmers In this post, you will know how to solve the AND Plus OR Codechef Solution. The Problem Code: ANDOR

AND Plus OR Codechef Solution
AND Plus OR Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

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

Ezoicreport this adAND 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 BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Subtraction Game 1 Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad