Number Game
Time limit2sMemory limit1024 MB
Given 1 to N on a board, repeatedly replace two numbers with their absolute difference. Maximize the final number and print the operations.
- Level
Medium6 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
A board has the distinct integers through . Repeat the following until only one integer remains on the board.
- Choose two integers on the board, erase them, and write the absolute difference of the two numbers.
For example, with on the board, choosing and leaves . Then choosing the two s leaves .
What must be done to make the final remaining integer as large as possible?
Input
The first line contains an integer . ()
Output
On the first line, print the largest integer that can remain at the end.
Then print lines. For every , the -th line contains the two integers chosen in the -th operation, separated by a space.