GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Thursday, 26 May 2022

[Solution] Or Permutation CodeChef Solution | CodeChef Problem Solution 2022

Chef has a sequence A of N integers. He picked a non-negative integer X and obtained another sequence B of N integers, defined as Bi=AiX for each 1iN. Unfortunately, he forgot X, and the sequence B got jumbled.

Chef wonders what the value of X is. He gives you the sequence A and the jumbled sequence B. Your task is to find whether there is a non-negative integer X such that there exists a permutation C of B satisfying the condition Ci=AiX for each 1iN.

Solution Click Below:-  CLICK HERE

If there are multiple such X, find any of them.

Note: Here | represents the bitwise OR operation.

Input Format

  • The first line of the input contains a single integer, T, denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of 3 lines of input.
    • The first line of each test case contains a single integer N.
    • The second line of each test case contains N space-separated integers, denoting the sequence A.
    • The third line of each test case contains N space-separated integers, denoting the sequence B.

Output Format

  • For each test case, output on a new line a single non-negative integer X that satisfies the given condition. If there is no such X, print 1 instead.

Constraints

  • 1T104
  • 1N2105
  • 0Ai,Bi109 for each 1iN
  • The sum of N over all test cases doesn't exceed 

No comments:

Post a Comment