結果

問題 No.1243 約数加算
ユーザー poohbearpoohbear
提出日時 2020-10-02 22:56:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,285 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 201,068 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-09-24 22:32:27
合計ジャッジ時間 5,892 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
 


void solve(ll a,ll b){
    vector<ll>ans;
    ll f = a;
    while(a!=b){
        if(a*a<=b){
            ans.push_back(a);
            a *= 2;
        }
        else{
            ll tmp = a;
            while(a+tmp>b){
                if(tmp%2!=0)break;
                tmp /= 2;
            }
            if(a+tmp<=b){
                ans.push_back(tmp);
                a += tmp;
            }
            /*
            else{
                for(int i=2;i<=a;i++){
                    if(a%i!=0)continue;
                    ll now = a/i;
                    if(a+now<=b){
                        a += now;
                        ans.push_back(now);
                        break;
                    }
                }
            }
            */
            else{
                for(int i=2;i<=f;i++){
                    if(f%i!=0)continue;
                    ll now = f/i;
                    if(a+now<=b){
                        a += now;
                        ans.push_back(now);
                        break;
                    }
                }
            }
        }
    }
    cout << ans.size() << endl;
    rep(i,ans.size()-1){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size()-1] << endl;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    ll t;
    cin >> t;
    rep(test,t){
        ll a,b;
        cin >> a >> b;
        solve(a,b);
    }

    return 0;
}
0