結果

問題 No.1243 約数加算
ユーザー IKyoproIKyopro
提出日時 2020-10-02 22:11:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 201,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 20:52:03
合計ジャッジ時間 3,106 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

void solve(){
    ll A,B;
    cin >> A >> B;
    vec<ll> ans;
    if(A%2==1){
        ans.push_back(1);
        A++;
    }
    vec<ll> p(60,1);
    for(int i=1;i<60;i++) p[i] = p[i-1]*2;


    auto calc = [&](ll x){
        int c = 0;
        while(x%2==0){
            x /= 2;
            c++;
        }
        return c;
    };

    ll a = A;
    int n = 1;
    while(n<60){
        int b = calc(a);
        if(a+(1LL<<b)>B) break;
        ans.push_back(1LL<<b);
        a += 1LL<<b;
    }
    int id = 59;
    B -= a;
    while(B){
        while(B>=p[id]){
            ans.push_back(p[id]);
            B -= p[id];
        }
        id--;
    }
    int m = ans.size();
    assert(m<=120);
    cout << m << "\n";
    for(int i=0;i<m;i++) cout << ans[i] << (i!=m-1? " ":"\n");
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        solve();
    }
}
0