#C13542. Filter Prime Numbers from a List

    ID: 43092 Type: Default 1000ms 256MiB

Filter Prime Numbers from a List

Filter Prime Numbers from a List

You are given a list of elements. Your task is to filter out and output only the prime numbers from the list. A prime number is defined as a positive integer greater than 1 that has no divisors other than 1 and itself. Formally, a number \(n\) is prime if and only if \(n > 1\) and for every integer \(d\) with \(2 \le d \le \sqrt{n}\), \(d\) does not divide \(n\).

If the input list contains any non-integer element, output the exact error message: Error: Input list contains non-integer elements.

The list might be empty or might not contain any prime numbers. In such cases, output nothing (i.e. an empty line).

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated tokens. Each token should represent an integer. If any token is not a valid integer, the program should output an error message.

outputFormat

If the input is valid, output the prime numbers found in the list, in the same order as they appear in the input, separated by a space. If no prime numbers are found, output an empty line. If there is any invalid (non-integer) input, output exactly: Error: Input list contains non-integer elements.

## sample
10
1 2 3 4 5 6 7 8 9 10
2 3 5 7