Wednesday, June 8, 2022

Construct An Array

 Given an integer 

N, construct an array A of length N such that:

  • 1Ai1018 for all (1iN);
  • There exists a subsequence of length greater than 1 such that the gcd of all elements of the subsequence is i, for all 1iN.
    More formally, for all (1iN), there exists a subsequence S of array A such that the length of the subsequence is k(2kN) and gcd(S1,S2,,Sk)=i.

It can be proven that it is always possible to construct such A under given constraints. If there exist multiple such arrays, print any.

Input Format

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow.
  • The only line of each test case contains an integer N - the length of the array to be constructed.

Output Format

For each test case, output a single line containing N space-separated integers, denoting the elements of the array A. The ith of these N integers is the ith element of the array A.

If there exist multiple such arrays, print any.

Constraints

  • 1T103
  • 3N103
  • Sum of N over all test cases does not exceed 5103.

Sample Input 1 

2
3
4

Sample Output 1 

2 3 6
4 24 10 15

Explanation

Test case 1: A possible array satisfying all the conditions is [2, 3, 6]:

  • For i=1: Choose S=[A1,A2,A3]=[2,3,6]. Thus, gcd(2,3,6)=1.
  • For i=2: Choose S=[A1,A3]=[2,6]. Thus, gcd(2,6)=2.
  • For i=3: Choose S=[A2,A3]=[3,6]. Thus, gcd(3,6)=3.

Test case 2: A possible array satisfying all the conditions is [4, 24, 10, 15]:

  • For i=1: Choose S=[4,24,10,15]. Thus, gcd(4,24,10,15)=1.
  • For i=2: Choose S=[24,10]. Thus, gcd(24,10)=2.
  • For i=3: Choose S=[24,15]. Thus, gcd(24,15)=3.
  • For i=4: Choose S=[4,24]. Thus, gcd(4,24)=4

No comments:

Post a Comment