結果

問題 No.1243 約数加算
ユーザー HAPPA
提出日時 2020-10-03 18:46:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-18 04:45:59
合計ジャッジ時間 901 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    t = int(input())
    for _ in range(t):
        a, b = map(int, input().split())

        target = 0
        for i in reversed(range(60)):
            if not(a & (1 << i)) and b & (1 << i):
                target = i
                break

        cnt = 0
        res1 = []
        for i in range(60):
            if a & (1 << target):
                break
            elif a & (1 << i) and a + (1 << i) <= b:
                cnt += 1
                res1.append(1 << i)
                a += (1 << i)

        res2 = []
        for i in range(60):
            if not (a & (1 << i)) and (b & (1 << i)) and a + (1 << i) <= b:
                cnt += 1
                a += (1 << i)
                res2.append(1 << i)

        res = res1 + res2[::-1]
        print(cnt)
        print(*res)


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