Instagram
youtube
Facebook
Twitter

Python Good Set program Codechef solution

          Python Good Set program Codechef solution

Problem:

A set of integers is called good if there are not three distinct elements a, b, and c in it such that a + b = c.

Your task is simple. Just output any good set of n integers. All the elements in this set should be distinct and lie between 1 and 500, both inclusive.

Input

  • The first line of the input contains an integer T denoting the number of test cases. The descriptions of the T-test cases follow.
  • The only line of each test case contains an integer n, denoting the size of the needed good set.

Output

For each test case, output a single line containing n integers denoting the elements of the good set, in any order. There can be more than one possible good set, and you can output any one of them.

Constraints

  • 1≤T,n≤100

Sample Input:

5

Sample Output:

1 2 

1 2 4

1 2 4 16

3 2 15 6 10

Explanation:

Example 1 and 2. Any set of size less than or equal to 2 is good by definition.

Example 3 onwards For each pair of elements in the set, you can see that their sum doesn't exist in the set.

Solution:

for i in range(int(input(“Enter the number of terms: “))):

    n=int(input(“Enter the size of the needed good set:  “))

    for i in range(n):

        print(2*i+1, end=" ")

    print()

 

Steps to solve this problem:

  1. Ask the user to enter the number of the terms.
  2. In the loop, ask the user to enter the size of the needed set.
  3. Again in the loop, calculate 2*1+1 and print the result.