結果

問題 No.1243 約数加算
ユーザー HAPPA
提出日時 2020-10-03 18:22:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 585 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-18 04:45:53
合計ジャッジ時間 1,761 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    t = int(input())
    for _ in range(t):
        a, b = map(int, input().split())

        cnt = 0
        res = []
        while a != b:
            g = gcd(a, b)
            if (a // g) % 2:
                a += g
                cnt += 1
                res.append(g)
            elif (b // g) % 2:
                b -= g
                cnt += 1
                res.append(g)
        print(cnt)
        print(*res)


if __name__ == '__main__':
    resolve()
0