Octopus Game
Time limit1sMemory limit512 MB
Given two starting card values, output at most 50 moves that add a multiple of one card to the other and put a zero on one card, keeping all values within 10^18.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Implementation
- Solved
- No attempts yet
Problem
In some country, a tournament called Octopus Game is held.
In this round, participants solve a math puzzle. Each player starts with two cards. Initially, the first card contains and the second card contains .
Players act with their cards. Let the integers on a player's cards be and . The player first chooses an integer , then performs one of the following operations:
- Replace the integer on the first card with .
- Replace the integer on the second card with .
During play, the absolute value of an integer written on a card must not exceed ; otherwise something bad may happen. A player wins the round if, after at most 50 actions, one of the cards contains 0.
You are going to play the game, and of course you want to win.
Input
The only line of input contains the two integers and initially written on the cards ().
Output
The first line must contain , the number of actions the player wants to perform to put 0 on one of the cards (). You do not need to minimize the number of actions, but it must not exceed 50.
The following lines must each contain two space-separated integers and : the type of the corresponding action and the chosen integer .
If there are multiple valid solutions, you may output any of them. However, during the game, the absolute value of the integers on the cards must not exceed .
Hint
The first test needs only one action: add three times the integer on the first card to the integer on the second card.
In the second test, after the first action the cards contain and , respectively; after the second action they contain and .
In the third test, the integers on the cards are, in order, and , and , and , and , and , and , and .