結果

問題 No.1243 約数加算
ユーザー kimiyukikimiyuki
提出日時 2020-10-14 02:20:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2023-09-28 00:24:41
合計ジャッジ時間 2,424 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
9,740 KB
testcase_01 AC 28 ms
9,860 KB
testcase_02 AC 30 ms
9,908 KB
testcase_03 AC 29 ms
9,868 KB
testcase_04 AC 33 ms
9,736 KB
testcase_05 AC 40 ms
9,940 KB
testcase_06 AC 43 ms
9,932 KB
testcase_07 AC 32 ms
9,820 KB
testcase_08 AC 42 ms
9,968 KB
testcase_09 AC 28 ms
10,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math
from typing import *


def solve(a: int, b: int) -> List[int]:
    if a == b:
        return []

    c = []
    e = []
    if a % 2 == 1:
        a += 1
        c.append(1)
    if b % 2 == 1:
        b -= 1
        e.append(1)
    d = math.gcd(a, b)
    a //= d
    b //= d
    return c + [d * x for x in solve(a, b)] + e


# generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
def main():
    t = int(input())
    for i in range(t):
        a, b = map(int, input().split())
        c = solve(a, b)
        print(len(c))
        print(*c)


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