#K86432. Sort Primes in a List

    ID: 36863 Type: Default 1000ms 256MiB

Sort Primes in a List

Sort Primes in a List

Given a list of \( n \) integers, your task is to sort only the prime numbers in ascending order while keeping the positions of the non-prime numbers unchanged.

A prime number is defined as a natural number greater than 1 that has no divisors other than 1 and itself. In mathematical terms, a number \( p \) is prime if \( p > 1 \) and for all integers \( d \) with \( 2 \leq d \leq \sqrt{p} \), \( d \nmid p \).

inputFormat

The input is read from standard input. The first line contains an integer ( n ) representing the number of elements in the list. The second line contains ( n ) space-separated integers.

outputFormat

Output the modified list in which all prime numbers are sorted in ascending order while the non-prime numbers retain their original positions. Print the numbers on one line separated by a single space.## sample

6
7 4 2 10 3 8
2 4 3 10 7 8