#P5736. Prime Number Filtering

    ID: 18964 Type: Default 1000ms 256MiB

Prime Number Filtering

Prime Number Filtering

You are given $n$ positive integers (each not exceeding $10^5$). Your task is to store all the numbers in an array, remove those which are not prime, and output the remaining prime numbers in the order they appear in the input.

A number is considered prime if it is greater than 1 and has no divisors other than 1 and itself. For checking primality, you may use the standard trial division method up to \(\sqrt{n}\).

inputFormat

The input consists of two lines. The first line contains an integer $n$ which indicates the number of positive integers. The second line contains $n$ integers separated by spaces, each not exceeding $10^5$.

outputFormat

Output the prime numbers (if any) in the same order as they appear in the input. The numbers should be separated by a single space. If no prime number exists, output nothing.

sample

5
1 2 3 4 5
2 3 5