結果

問題 No.1243 約数加算
ユーザー ShibuyapShibuyap
提出日時 2020-10-06 20:01:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,334 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 203,160 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 08:52:15
合計ジャッジ時間 3,097 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int main() {
    int T; cin >> T;
    rep(_,T){
        ll a, b;
        cin >> a >> b;
        if(b - a == 1){
            cout << 1 << endl;
            cout << 1 << endl;
            continue;
        }
        bitset<100> c(a);
        bitset<100> d(b);
        // cout << c << endl << d << endl;

        int ma = 0;
        rep(i,100){
            if(c[i]==0&&d[i]) ma = i;
        }
        // cout << ma << endl;

        vector<ll> ans;
        while(c[ma] == 0){
            rep(i,100){
                if(c[i]){
                    a += 1LL << i;
                    ans.push_back(1LL<<i);
                    bitset<100> cc(a);
                    c = cc;
                    break;
                }
            }
        }

        drep(i,ma){
            if(d[i]){
                ans.push_back(1LL<<i);
            }
        }

        cout << ans.size() << endl;
        rep(i,ans.size()){
            if(i > 0) cout << ' ';
            cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}
 
 
0