CODING QUESTION 3

Odd Sum (CODECHEF OCTOBER COOK-OFF CHALLENGE 2021)

 Given an integer 

, consider all arrays  of size 

  • All the elements are non-negative and distinct.
  • All prefix sums are odd. Formally, for all i such that  is odd.

Among all possible arrays , output the smallest possible sum of the elements of the array.

Note: Since the Input/Output may be large, it is preferred to use fast I/O.

Input Format

  • The first line contains  - the number of test cases. Then the test cases follow.
  • The first line of each test case contains  - the size of the array.

Output Format

For each test case, output on one line the smallest sum among all arrays satisfying the constraints.

Constraints



Sample Input 1 

1
3

Sample Output 1 

3

Explanation

  • Test case : A possible array is  is not valid because  occurs twice in it;  is not valid because the prefix sum until the first index is , which is even. Another possible array is  yields the sum , and we can prove that there are no valid arrays that have sum less than .

CODE:

for _ in range(int(input())):
    n=int(input())
    print((n-2)*(n-1)+1)

LINK: https://www.codechef.com/COOK134C/problems/ODDSUM

Please follow my page for more updates.....!

Comments

Popular posts from this blog