#K53082. Extract Prime Numbers

    ID: 29452 Type: Default 1000ms 256MiB

Extract Prime Numbers

Extract Prime Numbers

You are given a string that contains a list of space-separated integers. Your task is to extract all the prime numbers from the list and output them in the order they appeared in the input, separated by commas. If there are no prime numbers, output an empty string.

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In mathematical terms, a number \( n \) is prime if and only if \( n > 1 \) and for every integer \( a \) such that \( 2 \leq a \leq \sqrt{n} \), \( a \) does not divide \( n \) evenly.

For example:

  • If the input is "2 3 5 7 11", then the output should be "2,3,5,7,11".
  • If the input is "4 6 8 10 12", then the output should be an empty string.

inputFormat

The input consists of a single line containing space-separated integers.

Input Format:

integer1 integer2 ... integerN

outputFormat

Output a single line containing the prime numbers found in the input, separated by commas. If no prime numbers are found, output an empty string.

Output Format:

prime1,prime2,...,primeK
## sample
2 3 5 7 11
2,3,5,7,11