結果

問題 No.1243 約数加算
ユーザー IKyoproIKyopro
提出日時 2020-10-02 21:44:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,165 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 203,640 KB
実行使用メモリ 813,668 KB
最終ジャッジ日時 2023-09-23 04:31:19
合計ジャッジ時間 7,098 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 MLE -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

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++;
    }
    ll a = A;
    while(a<=B/A){
        ans.push_back(A);
        a *= A;
    }
    vec<ll> p = {1};
    int n = 0;
    for(int i=0;i<60;i++) if(a>>i&1) n = i;
    for(int i=1;i<=n;i++) p.push_back(1LL<<i);
    int id = n-1;
    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