結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,856 KB
testcase_01 AC 34 ms
9,812 KB
testcase_02 AC 33 ms
9,804 KB
testcase_03 AC 33 ms
9,988 KB
testcase_04 AC 35 ms
9,888 KB
testcase_05 AC 42 ms
9,836 KB
testcase_06 AC 49 ms
9,980 KB
testcase_07 AC 36 ms
9,892 KB
testcase_08 AC 49 ms
9,932 KB
testcase_09 AC 32 ms
10,032 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