#C14622. Filter Prime Numbers

    ID: 44292 Type: Default 1000ms 256MiB

Filter Prime Numbers

Filter Prime Numbers

You are given a list of integers. Your task is to filter out the non-prime numbers and output the prime numbers in the order they appear in the input.

A prime number is defined as a natural number greater than 1 that has no positive divisors other than 1 and itself. In mathematical notation, a number \( p \) is prime if and only if \( p > 1 \) and the only divisors of \( p \) are 1 and \( p \).

Input: The first line contains a single integer \( n \) representing the number of elements in the list. The second line contains \( n \) space-separated integers.

Output: Print the prime numbers from the list in their original order, separated by a single space. If there are no prime numbers, output an empty line.

inputFormat

The input is read from stdin as follows:

  • The first line contains an integer \( n \) (\( 1 \leq n \leq 10^5 \)).
  • The second line contains \( n \) space-separated integers. Each integer \( a_i \) can be any 32-bit signed integer.

outputFormat

Output the prime numbers from the list to stdout in one line, separated by a single space. If there are no prime numbers, output an empty line.

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