QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#1900. 章鱼游戏

الإحصائيات

“章鱼游戏”锦标赛在某个国家举行。

本轮比赛中,参赛者将面对一道数学谜题。每位选手有两张卡片,初始时卡片上的整数分别为 $a_0$ 和 $b_0$。

选手可以对卡片进行操作。设选手卡片上的整数为 $a$ 和 $b$。选手首先选择一个整数 $k$,然后执行以下操作之一:

  1. 将第一张卡片上的整数替换为 $a + kb$;
  2. 将第二张卡片上的整数替换为 $b + ka$。

在游戏过程中,卡片上整数的绝对值不得超过 $10^{18}$,否则可能会发生糟糕的事情。如果在最多 50 次操作后,其中一张卡片上的数字变为 0,则该选手赢得本轮比赛。

你将参加这场游戏,当然,你想要获胜!

输入格式

输入仅一行,包含两个整数 $a_0$ 和 $b_0$ —— 卡片上的初始整数($-10^{18} \le a_0, b_0 \le 10^{18}$)。

输出格式

第一行必须包含 $n$ —— 选手为使其中一张卡片变为 0 而执行的操作次数($0 \le n \le 50$)。注意,你不必最小化操作次数,但次数不得超过 50。

接下来的 $n$ 行,每行包含两个空格分隔的整数:$t_i$ 和 $k_i$ —— 分别表示操作类型和选择的整数 $k$。

如果存在多种有效的解决方案,输出其中任意一种即可,但请注意,在游戏过程中,卡片上的整数绝对值不得超过 $10^{18}$。

样例

样例输入 1

-3 9

样例输出 1

1
2 3

样例输入 2

-27 57

样例输出 2

2
2 2
1 9

样例输入 3

56 15

样例输出 3

6
1 -2
1 -1
2 -2
1 1
2 2
1 -4

说明

第一个测试用例仅需一次操作:将第二张卡片上的整数加上第一张卡片上整数的 3 倍。

第二个测试用例:第一次操作后,卡片上的整数分别为 $-27$ 和 $3$,第二次操作后,卡片上的整数分别为 $0$ 和 $3$。

第三个测试用例:卡片上的整数依次为:$56$ 和 $15$,$26$ 和 $15$,$11$ 和 $15$,$11$ 和 $-7$,$4$ 和 $-7$,$4$ 和 $1$,$0$ 和 $1$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.