結果

問題 No.1243 約数加算
コンテスト
ユーザー srjywrdnprkt
提出日時 2024-04-09 14:17:56
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 912 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,146 ms
コンパイル使用メモリ 217,244 KB
実行使用メモリ 11,944 KB
最終ジャッジ日時 2026-07-04 11:08:52
合計ジャッジ時間 1,943 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve(){

    // 010100110
    // 010101000
    // 010110000
    // 011000000
    // 100000000

    // 100101011
    ll A, B;
    cin >> A >> B;
    vector<ll> ans;

    //1,Bの最上位以外のbitを0にする(下から)
    for (int i=0; i<60; i++){
        if ((A>>i & 1) && A+(1LL<<i)<=B){
            A += (1LL<<i);
            ans.push_back((1LL<<i));
        }
    }

    //2,Bと立っているbitを揃える(上から)
    for (int i=59; i>=0; i--){
        if ((B>>i & 1) && !(A>>i & 1)){
            A += (1LL<<i);
            ans.push_back((1LL<<i));
        }
    }

    assert(A == B);
    cout << ans.size() << endl;
    for (auto x : ans) cout << x << " ";
    cout << endl;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int T;
    cin >>  T;
    while(T--) solve();

    return 0;
}
0