GCD value

3

2 votes
Linear Algebra, Gaussian Elimination, Medium-Hard, Mathematics
Problem

You are given an array A that contains N elements and an integer K that represents the value of a non-empty subsequence B1,B2,,Bm of A is defined as (B1K)(B2K)(BmK)gcd (B1,B2,,Bm) (where  is the XOR operator). Determine the maximum value of any non-empty subsequence in the given array.

For example, if the elements of array A is [2, 4, 6] and K is 6, then the maximum value is achieved you select the subsequence [2,4]. In this case, the value of the subsequence will be ((26)(46))gcd (2,4)=62=12.

Note: A sequence b is a subsequence of a sequence a if b can be obtained from a by deleting several (possibly zero) elements. For this question, assume that if the sequence has a single element, then the gcd is the element itself.

Input format

  • First line: Two integers N and K (1N,K105), where N denotes the number of elements in the array
  • Second line: N integers A1,A2,,An (1Ai105) that denote the elements of the array

Output format

Print the maximum value of any non-empty subsequence of the given array.

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the given example it is clear that when we chose the subsequence containing only 6, we get the maximum value. Here gcd of elements in subsequence is 6 and K is 3. So, value = (6 ^ 3) * (6) = 5 * 6 = 30.

Editor Image

?