結果

問題 No.1243 約数加算
ユーザー kibunakibuna
提出日時 2020-10-02 22:05:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 169,152 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 12:33:30
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    vector<lint> a(t), b(t);
    for (int i = 0; i < t; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < t; ++i) {
        int nb    = 64 - __builtin_clzll(b[i]);
        int tp    = -1;
        lint curr = a[i];

        vector<lint> res;
        for (int j = nb - 1; j >= 0; --j) {
            if ((b[i] & 1LL << j) && !(a[i] & 1LL << j)) {
                tp = j;
                break;
            }
        }
        // assert(tp != -1);
        for (int j = 0; j < tp; ++j) {
            if (a[i] & 1LL << j) {
                a[i] += 1LL << j;
                res.push_back(1LL << j);
            }
        }
        if (!(a[i] & 1LL << tp)) {
            a[i] += 1LL << tp;
            res.push_back(1LL << tp);
        }
        for (int j = tp - 1; j >= 0; --j) {
            if ((b[i] & 1LL << j) && !(a[i] & 1LL << j)) {
                a[i] += 1LL << j;
                res.push_back(1LL << j);
            }
        }
        cout << res.size() << "\n";
        for (auto &r : res) {
            cout << r << " ";
            assert(curr % r == 0);
            curr += r;
        }
        assert(curr == b[i]);
        cout << endl;
    }
    return 0;
}
0