結果
| 問題 | 
                            No.1243 約数加算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tktk_snsn
                         | 
                    
| 提出日時 | 2020-10-02 23:51:52 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 818 bytes | 
| コンパイル時間 | 120 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 17,828 KB | 
| 最終ジャッジ日時 | 2024-07-18 00:30:46 | 
| 合計ジャッジ時間 | 4,016 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 4 TLE * 1 -- * 4 | 
ソースコード
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
def calc(A, B, tmp=[]):
    res = []
    res.extend(tmp)
    while A + A <= B:
        res.append(A)
        A += A
    cnt = 0
    X = A
    while X % 2 == 0:
        cnt += 1
        X >>= 1
    dif = B - A
    while dif:
        for i in reversed(range(cnt + 1)):
            val = 1 << i
            if dif >= val:
                dif -= val
                res.append(val)
                A += val
                if A % (val * 2) == 0:
                    cnt = max(cnt, i + 1)
                break
    if len(res) <= 120:
        print(len(res))
        print(*res, sep=" ")
        return
    calc(A+1, B, [1])
T = int(input())
query = tuple(tuple(map(int, input().split())) for _ in range(T))
for a, b in query:
    calc(a, b)
            
            
            
        
            
tktk_snsn