結果

問題 No.2104 Multiply-Add
ユーザー flygonflygon
提出日時 2022-10-21 23:34:28
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 927 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 86,540 KB
実行使用メモリ 78,720 KB
最終ジャッジ日時 2023-09-13 23:42:34
合計ジャッジ時間 6,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,204 KB
testcase_01 AC 73 ms
71,552 KB
testcase_02 AC 73 ms
71,100 KB
testcase_03 AC 72 ms
71,540 KB
testcase_04 AC 73 ms
71,128 KB
testcase_05 AC 74 ms
71,164 KB
testcase_06 AC 73 ms
71,236 KB
testcase_07 AC 74 ms
71,472 KB
testcase_08 AC 74 ms
71,252 KB
testcase_09 AC 75 ms
71,552 KB
testcase_10 AC 72 ms
71,292 KB
testcase_11 AC 74 ms
71,216 KB
testcase_12 AC 73 ms
71,536 KB
testcase_13 AC 73 ms
71,264 KB
testcase_14 AC 74 ms
71,220 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 71 ms
71,228 KB
testcase_19 AC 72 ms
71,260 KB
testcase_20 AC 71 ms
71,200 KB
testcase_21 AC 74 ms
71,476 KB
testcase_22 AC 70 ms
71,168 KB
testcase_23 AC 71 ms
71,212 KB
testcase_24 RE -
testcase_25 AC 70 ms
71,256 KB
testcase_26 AC 76 ms
71,152 KB
testcase_27 AC 72 ms
71,544 KB
testcase_28 AC 72 ms
71,280 KB
testcase_29 AC 73 ms
71,184 KB
testcase_30 AC 84 ms
71,392 KB
testcase_31 AC 81 ms
71,204 KB
testcase_32 AC 74 ms
71,476 KB
testcase_33 AC 82 ms
71,132 KB
testcase_34 AC 83 ms
71,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b,c,d = map(int,input().split())
c,d,a,b = a,b,c,d
from math import gcd
if gcd(a,b) != gcd(c,d):
  print(-1)
  exit()
cd = [[c,d]]
if c < 0:
  c = c + (abs(c)//abs(d)+1)*abs(d)
  cd.append([c,d])
if d < 0:
  d = d + (abs(d)//c+1)*c
  cd.append([c,d])
while c != 0 and d != 0:
  if c < d:
    d %= c
    cd.append([c,d])
  else:
    c %= d
    cd.append([c,d])
  
ab = [[a,b]]
if a < 0:
  a = a + (abs(a)//abs(b)+1)*abs(b)
  ab.append([a,b])
if b < 0:
  b = b + (abs(b)//a+1)*a
  ab.append([a,b])
while a != 0 and b != 0:
  if a < b:
    b %= a
    ab.append([a,b])
  else:
    a %= b
    ab.append([a,b])

if ab[-1] == cd[-1]:
  ab.pop()
  cd += ab[::-1]
else:
  ab.append([max(ab[-1]), max(ab[-1])])
  cd += ab[::-1]
print(len(cd)-1)
for i in range(1,len(cd)):
  c,d = cd[i]
  if c == cd[i-1][0]:
    dd = cd[i-1][1]
    tmp = (d - dd)//c
    print(2, tmp)
  else:
    cc = cd[i-1][0]
    tmp = (c-cc)//d
    print(1, tmp)

0