結果

問題 No.1243 約数加算
ユーザー betrue12betrue12
提出日時 2020-10-03 17:55:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 201,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 05:32:55
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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