MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CodeChef_problems/AND Plus OR/solution.cpp:3–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include<bits/stdc++.h>
2using namespace std;
3int main()
4 {
5 // This problem is basically a constructive algorithm type
6 // One of the important features of Constructive Algo is there are many solutions of the same problem can be possible
7 // I am sharing one of those solutions
8 // Constraints of the problem 1) Variable "t" for testcases can be from 1 to 10^5 2)
9 // 2) Input number "n" vary from 1 to 10^18
10 /* Basically what we need to do is, in the given input integer "n" we need to find two non-negative integers (starting with 0)
11 such that the sum of the bitwise OR and the bitwise AND of the two numbers is equal to the given number "n" .
12 Lets take two numbers a and b then , (a or b) + (a and b) == n */
13 // Simple solution could be to take 0 as "a" and n as "b" because any number when "or" with "0" will gives us the given number
14 // Similarly, any number when "and" with "0" will gives us 0
15 // so, n= (0 or n) + (0 and n)
16 int t; // taking variable t "int" (as t is atmost 10^5)
17 long long n; // taking the variable "n" of type long long (as n is atmost 10^18)
18 cin>>t; // t for testcases
19 while(t--) // looping till t!=0
20 {
21 cin>>n; // taking input of the number "n"
22 cout<<0<<" "<<n<<endl; // Simply printing 0 with n
23 }
24 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected