結果

問題 No.1243 約数加算
ユーザー FromBooskaFromBooska
提出日時 2023-02-22 12:29:40
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 1,114 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 79,728 KB
最終ジャッジ日時 2023-09-29 20:41:01
合計ジャッジ時間 5,149 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,448 KB
testcase_01 AC 71 ms
71,112 KB
testcase_02 AC 73 ms
71,572 KB
testcase_03 AC 99 ms
75,776 KB
testcase_04 AC 560 ms
77,600 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 2**120 > 1**18なので、1から10**18まで120回で達することができる
# まず最大値より大きければどんどん大きくするのがいい、貪欲的
# 入力例1の(26, 57)で、26未満の約数を最初に加えるメリットはない
# 26+26とすれば、26の約数はすべてキープされて後でも使えるから
# 毎回約数をリストすると間に合わないか

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())
    ans = []
    if B >= A*2:
        ans.append(A)
        A *= 2

    from bisect import *
    while B > A:
        divs = divisors(A) # Aの約数は変わっていく
        idx = bisect_left(divs, B-A+1)
        ans.append(divs[idx-1])
        #print(B, A, divs, divs[idx-1])
        A += divs[idx-1]
    print(len(ans))
    print(*ans)
0