#C12667. Sort with Primes First
Sort with Primes First
Sort with Primes First
Given a list of integers, your task is to rearrange the list so that all prime numbers appear first, sorted in ascending order, followed by all non-prime numbers sorted in ascending order. Recall that a number \( p \) is prime if and only if \( p > 1 \) and its only positive divisors are 1 and \( p \), i.e., \(\forall d \ (d \mid p \implies d = 1 \lor d = p)\).
You need to read input from STDIN and output the result to STDOUT. The input consists of space-separated integers on a single line. The output should be the rearranged list of integers, where the numbers are separated by a single space.
inputFormat
The input is provided on a single line via STDIN. The line contains space-separated integers. For example: 3 8 5 2 11 4
outputFormat
Output a single line containing the rearranged integers separated by a space. The prime numbers (in ascending order) must come first, followed by the non-prime numbers (also in ascending order). For example, for the sample input above, the output should be: 2 3 5 11 4 8
3 8 5 2 11 4
2 3 5 11 4 8