#C7004. Organizing Books Based on ISBN Prime Status
Organizing Books Based on ISBN Prime Status
Organizing Books Based on ISBN Prime Status
You are given a list of ISBN numbers of books. The task is to rearrange the list such that all books with prime ISBNs appear first, followed by the books with non-prime ISBNs. The relative order of the books in each group (prime and non-prime) should remain the same as in the original list.
A number \(p\) is considered prime if \(p > 1\) and it has no positive divisors other than 1 and itself. For example, the ISBN \(2\) is prime while \(1\) is not.
Example: If the number of books is n = 5 and the list is [3, 1, 4, 2, 5], the output should be [3, 2, 5, 1, 4].
inputFormat
The input is read from stdin and formatted as follows:
- The first line contains an integer n, representing the number of books.
- The second line contains n space-separated integers representing the ISBN numbers of the books.
outputFormat
Output a single line to stdout containing the rearranged ISBN numbers separated by a single space.
## sample5
3 1 4 2 5
3 2 5 1 4
</p>