結果

問題 No.1243 約数加算
ユーザー qwewe
提出日時 2025-04-24 12:21:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 70,856 KB
最終ジャッジ日時 2025-04-24 12:23:39
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def largest_divisor(current, X):
    if X <= 0:
        return None
    if current % X == 0:
        return X
    max_d = 1
    sqrt_current = int(math.isqrt(current))
    for i in range(1, sqrt_current + 1):
        if current % i == 0:
            if i <= X and i > max_d:
                max_d = i
            j = current // i
            if j <= X and j > max_d:
                max_d = j
    return max_d if max_d != 0 else None

def solve():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    T = int(input[idx])
    idx += 1
    for _ in range(T):
        A = int(input[idx])
        B = int(input[idx + 1])
        idx += 2
        
        if (B - A) > 0 and A % (B - A) == 0:
            print(1)
            print(B - A)
            continue
        
        path = []
        current = B
        found = False
        while current > A:
            X = current - A
            d = largest_divisor(current, X)
            if d is None:
                d = 1
            path.append(d)
            current -= d
            if len(path) > 120:
                break
        
        path = path[::-1]
        print(len(path))
        print(' '.join(map(str, path)))

if __name__ == "__main__":
    solve()
0