結果

問題 No.1243 約数加算
ユーザー hiro71687khiro71687k
提出日時 2023-03-03 07:10:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,226 bytes
コンパイル時間 4,320 ms
コンパイル使用メモリ 263,780 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 00:47:35
合計ジャッジ時間 5,095 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=double;
ld pie=3.14159265359;
ll mod=998244353;
long long inf=100000000000000001;
int main(){
    ll t;
    cin >> t;
    vector<ll>two(62,1);
    for (ll i = 1; i < two.size(); i++)
    {
        two[i]=two[i-1]*2;
    }
    for (ll o = 0; o < t; o++)
    {
        ll a,b;
        cin >> a >> b;
        ll x=b-a;
        ll now=0;
        for (ll i = 0; i <=60; i++)
        {
            if (a%two[i]==0)
            {
                now=max(now,i);
            }
        }
        vector<ll>ans;
        ll aa=a;
        while (two[now]<x)
        {
            if (aa%two[now+1]==0)
            {
                now+=1;
                continue;
            }
            ans.push_back(two[now]);
            aa+=two[now];
            x-=two[now];
            now+=1;
        }
        for (ll i = 60; i >=0; i--)
        {
            if (two[i]&x)
            {
                ans.push_back(two[i]);
            }
        }
        cout << ans.size() << endl;
        for (ll i = 0; i < ans.size(); i++)
        {
            cout << ans[i]<< ' ';
        }
        cout << endl;
    }
    
}
0