結果

問題 No.1243 約数加算
ユーザー poohbearpoohbear
提出日時 2020-10-03 11:54:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,704 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 201,440 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 05:00:55
合計ジャッジ時間 5,169 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
 


void solve(ll a,ll b){
    int high_order_bit = 0;
    for(int i=60;i>=0;i--){
        if((!(a>>i))&&(b>>i)){
            high_order_bit = i;
            break;
        }
    }
    vector<ll>ans;
    ll now = 1;
    for(int i=0;i<high_order_bit;i++){
        if((a>>i)&1){
            ans.push_back(now);
            a += now;
        }
        now *= 2;
    }
    now /= 2;
    for(int i=high_order_bit-1;i>=0;i--){
        if((b>>i)&1){
            ans.push_back(now);
        }
        now /= 2;
    }
    cout << ans.size() << endl;
    rep(i,ans.size()-1){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size()-1] << endl;
    return;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    ll t;
    cin >> t;
    rep(test,t){
        ll a,b;
        cin >> a >> b;
        solve(a,b);
    }

    return 0;
}
0