結果

問題 No.1243 約数加算
ユーザー betrue12
提出日時 2020-10-03 17:55:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 1,965 ms
コンパイル使用メモリ 195,772 KB
最終ジャッジ日時 2025-01-15 02:10:46
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

void solve(){
    int64_t A, B;
    cin >> A >> B;
    vector<int64_t> ans;
    for(int k=0; k<60; k++) if(nth_bit(A, k) && A + (1LL<<k) <= B){
        ans.push_back(1LL<<k);
        A += 1LL<<k;
    }
    for(int k=59; k>=0; k--) if(!nth_bit(A, k) && nth_bit(B, k)){
        ans.push_back(1LL<<k);
        A += 1LL<<k;
    }
    int sz = ans.size();
    cout << sz << endl;
    for(int i=0; i<sz; i++) cout << ans[i] << " \n"[i==sz-1];
    cerr << A << " " << B << endl;
}

int main(){
    int T;
    cin >> T;
    while(T--) solve();
}
0