#C13237. Extract Prime Numbers

    ID: 42753 Type: Default 1000ms 256MiB

Extract Prime Numbers

Extract Prime Numbers

You are given a list of numbers. Your task is to extract all the prime numbers from the list and print them in the same order as they appear. A positive integer \( n \) is defined as prime if \( n > 1 \) and it has no divisors other than 1 and itself. In other words, for any integer \( k \) with \( 2 \le k \le \sqrt{n} \), \( n \mod k \neq 0 \).

The function must also check the input:

  • If any element is not an integer, output: All elements must be integers.
  • If any element is negative, output: Negative numbers are not allowed.

Input is read from standard input (stdin) and output should be printed to standard output (stdout). The output for a valid input should be the list of prime numbers in Python list format (e.g., [2, 3, 5]).

inputFormat

The first line contains a single integer T, representing the number of elements in the list. The second line contains T space-separated tokens. These tokens should represent integers.

outputFormat

If all tokens are valid and non-negative integers, print a list (in Python list format) containing only the prime numbers extracted from the input, preserving their original order. If any token is not a valid integer, print exactly All elements must be integers. If any integer is negative, print exactly Negative numbers are not allowed.

## sample
7
2 3 5 10 15 17 23
[2, 3, 5, 17, 23]