#K5921. Prime Sequences and Sum

    ID: 30814 Type: Default 1000ms 256MiB

Prime Sequences and Sum

Prime Sequences and Sum

You are given T test cases. For each test case, you are provided with an integer N. Your task is to generate the first N prime numbers and then append the sum of these primes at the end of the sequence.

For example, if N = 2, the first two primes are 2 and 3, and their sum is 5. Hence, the output for this test case should be: 2 3 5.

The answer for each test case should be printed on a separate line. All numbers in the sequence are separated by a single space.

Note: A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. In mathematical terms, a number p is prime if it satisfies the condition \(p > 1\) and \(\forall 1< d <p,\ p\ \%\ d \neq 0\).

inputFormat

The input is provided via standard input (stdin) and consists of multiple lines:

  1. The first line contains an integer T, the number of test cases.
  2. The following T lines each contain a single integer N.

Constraints:

  • 1 \(\leq T \leq 100\)
  • 1 \(\leq N \leq 50\)

outputFormat

For each test case, output a single line containing the first N prime numbers followed by their sum. All numbers must be separated by a single space.

For example, for an input test case with N = 2, the output should be:

2 3 5
## sample
3
2
3
5
2 3 5

2 3 5 10 2 3 5 7 11 28

</p>