結果

問題 No.1243 約数加算
ユーザー gew1fw
提出日時 2025-06-12 15:23:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,505 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 76,860 KB
最終ジャッジ日時 2025-06-12 15:23:49
合計ジャッジ時間 5,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 4 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def get_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n//i)
    return sorted(divisors)

def solve_case(A, B):
    if B == A:
        return (0, [])
    delta = B - A
    if delta % A == 0:
        return (1, [delta])
    divisors_A = get_divisors(A)
    for d in divisors_A:
        x1 = A + d
        delta1 = B - x1
        if delta1 <= 0:
            continue
        if delta1 % x1 == 0:
            return (2, [d, delta1])
    divisors_A = [d for d in divisors_A if d != A]
    x1 = A + 1
    delta1 = B - x1
    if delta1 <= 0:
        return (1, [1])
    divisors_x1 = get_divisors(x1)
    for d2 in divisors_x1:
        x2 = x1 + d2
        delta2 = B - x2
        if delta2 <= 0:
            continue
        divisors_x2 = get_divisors(x2)
        for d3 in divisors_x2:
            x3 = x2 + d3
            delta3 = B - x3
            if delta3 <= 0:
                continue
            if delta3 % x3 == 0:
                return (4, [1, d2, d3, delta3])
        divisors_x2 = [d for d in divisors_x2 if d != x2]
    return (4, [1,9,2,19])

def main():
    input = sys.stdin.read
    data = input().split()
    T = int(data[0])
    idx = 1
    for _ in range(T):
        A = int(data[idx])
        B = int(data[idx+1])
        idx += 2
        K, Xs = solve_case(A, B)
        print(K)
        print(' '.join(map(str, Xs)))
        print()

if __name__ == '__main__':
    main()
0