結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
9,964 KB
testcase_01 AC 33 ms
9,992 KB
testcase_02 AC 31 ms
9,956 KB
testcase_03 AC 33 ms
9,828 KB
testcase_04 AC 36 ms
10,016 KB
testcase_05 AC 43 ms
9,848 KB
testcase_06 AC 47 ms
10,040 KB
testcase_07 AC 36 ms
10,012 KB
testcase_08 AC 48 ms
9,932 KB
testcase_09 AC 32 ms
9,864 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