結果

問題 No.1243 約数加算
コンテスト
ユーザー H20
提出日時 2021-04-13 09:51:33
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 977 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 218 ms
コンパイル使用メモリ 84,864 KB
実行使用メモリ 81,152 KB
最終ジャッジ日時 2026-03-18 13:37:50
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 7 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math
T = int(input())
for _ in range(T):
    A,B = map(int,input().split())
    ANS = []
    if int(math.log2(A))!=int(math.log2(B)):
        if math.log2(A) != int(math.log2(A)):
            for i in range(math.ceil(math.log2(A))):
                if 2**i & A == 2**i:
                    A += 2**i
                    ANS.append(2**i)
        while int(math.log2(A))!=int(math.log2(B)):
            ANS.append(A)
            A*=2
        AB = format(A, 'b')
        for i in range(len(AB)):
            AB = format(A, 'b')
            BB = format(B, 'b')
            if AB[i] != BB[i]:
                ANS.append(2**(len(AB)-i-1))
                A+=2**(len(AB)-i-1)
    else:
        AB = format(A, 'b')
        for i in reversed(range(len(AB))):
            AB = format(A, 'b')
            BB = format(B, 'b')
            if AB[i] != BB[i]:
                A += (2**(len(AB)-i-1))
                ANS.append((2**(len(AB)-i-1)))

    print(len(ANS))
    print(*ANS)

0