結果

問題 No.1243 約数加算
ユーザー totori_nyaatotori_nyaa
提出日時 2020-10-02 21:55:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,258 bytes
コンパイル時間 2,602 ms
コンパイル使用メモリ 201,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-23 04:52:39
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    int q; cin>>q;
    while(q--){
        ll a,b;
        cin>>a>>b;
        vector<ll> ans;
        if(a%2){
            ans.push_back(1);
            a++;
        }
        ll now = 1;
        ll dif = b - a;
        while(dif>=1 && now<62){
            if(dif>=(1LL<<(now-1)) && a%(1LL<<now)){
                ans.push_back(1LL<<(now-1));
                dif -= (1LL<<now-1);
                a += (1LL<<(now-1));
            }
            now++;
        }
        now = 61;
        while(dif){
            if(dif & (1LL<<now)){
                ans.push_back(1LL<<now);
                a += (1LL<<now);
                dif -= (1LL<<now);
            }
            now--;
        }
        cout << ans.size() << "\n";
        for(int i=0;i<ans.size();i++){
            if(i)cout << " ";
            cout << ans[i];
        }
        cout << "\n";
    }

}
0