Two equations You are given the following equations: • a+b=x • a XOR b = y You are given Q queries containing the values

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Two equations You are given the following equations: • a+b=x • a XOR b = y You are given Q queries containing the values

Post by answerhappygod »

Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 1
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 1 (187.62 KiB) Viewed 51 times
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 2
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 2 (198.21 KiB) Viewed 51 times
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 3
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 3 (159.4 KiB) Viewed 51 times
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 4
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 4 (241.97 KiB) Viewed 51 times
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 5
Two Equations You Are Given The Following Equations A B X A Xor B Y You Are Given Q Queries Containing The Values 5 (157.96 KiB) Viewed 51 times
Two equations You are given the following equations: • a+b=x • a XOR b = y You are given Q queries containing the values of x and y. Task Determine the possible values of a and b or print -1 if it does not exist. Example Assumptions X=6 Approach You must determine the value of a and b (if exists) such that it meets the given conditions:
Approach You must determine the value of a and b (if exists) such that it meets the given conditions: e If you choose a = 1 and b = 5 then, (a + b) = (1 + 5) = 6 = x • (a xor b) = (1 xor 5) = 4 = y e Therefore the answer is a = 1 and b = 5. Function description 32°C Complete the solve function provided in the editor. This function takes the following 2 parameters: x. Represents the first integer value • y. Represents the second integer value Input format Note: This is the input format that you must use to provide custom Input (available above the Compile and Test button). • The first line of input contains Q denoting the number of queries, • Each of the next Q lines contains two space-separated integers x and y.
Output format For each query, print the space-separated integer solution (a, b) or -1 on a new line. Notes • If there exists more than one solution, then print the pair (a, b) with the smallest possible value of a. • If there exists no solution, then print -1. Constraints 1≤Q<106 0≤x, y < 1018 Code snippets (also called starter code/boilerplate code) This question has code snippets for C, CPP, Java, and Python. Sample input 5 2 42 34 Sample output
Explanation The first line represents the number of test cases, f = 2 The first test case x = 4 and y = 2 a+b = 4 a XOR b = 2 a = 1 and b = 3 are the smallest pairs that satisfy the given two equations. pairs The second test case x = 3 and y = 4 The answer does not exist. Hence output -1.
1 #include<stdio.h> 2 #include<stdbool.h> 3 #include<malloc.h> 5 7 8 9 10 11 12 13 15 16 17 18 19 void solve (long long x, long long y) { // write your code here int main() { int T; 21 } scanf("%d", &T); for(int t_i = 0; t_i < T; t_ií) { } long long x; scanf("%lld", &x); long long y; scanf("%lld", &y); solve(x, y);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply