問題一覧 > 通常問題

No.2104 Multiply-Add

レベル : / AI推定難易度 : 1350 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 63
作問者 : Sumitacchan / テスター : 👑 hitonanode ygussany
お気に入りにしたユーザー ProblemId : 8327 / 自分の提出
問題文最終更新日: 2022-10-08 11:11:47
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 365 (順位表) の他の問題:

Problem Statement

There are $2$ variables $x,y$, and initially $(x,y)=(a,b)$.

You may perform the following operations in any order, up to $1000$ times in total (possibly $0$ times).

  • Operation $1$ : Choose an integer $k\ (-10^9 \le k \le 10^9)$ and add $k \times y$ to $x$.
  • Operation $2$ : Choose an integer $k\ (-10^9 \le k \le 10^9)$ and add $k \times x$ to $y$.
However, $|x|\le 10^9,|y|\le 10^9$ must be satisfied after each operation.

Determine whether it is possible to make $(x,y)=(c,d)$ by the above operations, and if it is possible, show one such sequence of operations.

Constraints

  • $-10^8 \le a,b,c,d \le 10^8$
  • All inputs are integers.

Input

The input is given from standard input in the following format.

$a\ \ b\ \ c\ \ d$

Output

If it is impossible to make $(x,y)=(c,d)$, print $-1$.

If it is possible to make $(x,y)=(c,d)$, print such a sequence of operations in the following format (if there are multiple sequences of operations satisfying the conditions, you may print any of them).

$N$
$t_1\ \ k_1$
$t_2\ \ k_2$
$\vdots$
$t_N\ \ k_N$
Here, $N$ is the number of operations, and $t_i,k_i\ (1\le i\le N)$ are the type of the $i$-th operation and the value of $k$ chosen in it, respectively.
Each of them must be an integer satisfying the following conditions.

  • $0 \le N\le 1000$
  • $t_i=1$ or $t_i=2$
  • $-10^9\le k_i \le 10^9$

Sample

Sample 1
Input
5 1 -10 19
Output
4
1 3
2 1
1 -2
2 -1

With the $4$ operations, $(x,y)$ changes as follows.
$(5,1) \rightarrow (8,1) \rightarrow (8,9) \rightarrow (-10,9) \rightarrow (-10,19)$

Sample 2
Input
0 0 1 -1
Output
-1

No matter how many operations are performed, $(x,y)=(0,0)$ remains unchanged.

Sample 3
Input
123 456 123 456
Output
0

$(x,y)=(c,d)$ is satisfied from the beginning.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。