Well-Read
Time limit2sMemory limit512 MB
Given n students who each hold a different book, output at most 4950 pairwise swaps so that every student eventually holds every book.
- Level
Medium6 of 10
- Topics
- Implementation, Recursion
- Solved
- No attempts yet
Problem
There are students at FER, numbered 1, 2, ..., . They decide to read classic works of world literature. Each student buys one book, and all the books are different. Then they read every purchased book by exchanging books with each other.
At every moment, each student holds exactly one of the books. At the start, each student holds the book they bought. When two students finish the books they currently hold, they can swap books.
Organize the swaps so that every student eventually obtains every book. The total number of swaps must be at most 4950.
Input
A single natural number , the number of students. It satisfies .
Output
Print at most 4950 swaps, one per line, in the order they happen. Write each swap as two integers separated by a space, the numbers of the two students who exchange books.