結果

問題 No.1243 約数加算
ユーザー titiatitia
提出日時 2020-10-02 21:58:31
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-09-24 12:15:15
合計ジャッジ時間 1,345 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,768 KB
testcase_01 AC 16 ms
7,800 KB
testcase_02 AC 15 ms
7,860 KB
testcase_03 AC 16 ms
7,872 KB
testcase_04 AC 24 ms
8,320 KB
testcase_05 AC 53 ms
8,316 KB
testcase_06 AC 65 ms
7,780 KB
testcase_07 AC 35 ms
8,192 KB
testcase_08 AC 67 ms
7,816 KB
testcase_09 AC 16 ms
7,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

T=int(input())
for tests in range(T):
    A,B=map(int,input().split())
    ANS=[]

    while True:
        for i in range(80):
            if (1<<i)>B:
                target=(1<<(i-1))
                break

        if A>target:
            A-=target
            B-=target
        else:
            break
    
    while A<target:
        X=A
        twos=1
        while X%2==0:
            X//=2
            twos*=2

        ANS.append(twos)
        A+=twos

    B-=A
    while B!=0:
        for i in range(80):
            if (1<<i)>B:
                break
        ANS.append(1<<(i-1))
        B-=1<<(i-1)

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