結果

問題 No.1243 約数加算
ユーザー FromBooskaFromBooska
提出日時 2023-02-20 14:58:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 755 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 844,348 KB
最終ジャッジ日時 2023-09-28 12:56:09
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,408 KB
testcase_01 AC 75 ms
71,320 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 貪欲法でいいのか? 差を約数の大きいほうから使っていって埋める
# 約数は1を含むので近づきすぎるということはないはず

def divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

T = int(input())
for t in range(T):
    A, B = map(int, input().split())
    B_A = B-A
    divs = divisors(A)[::-1]
    ans = []
    for d in divs:
        if B_A >= d:
            temp = [d]*(B_A//d)
            ans.extend(temp)
            B_A -= d*(B_A//d)
    print(len(ans))
    print(*ans)
0