結果

問題 No.1243 約数加算
ユーザー monnumonnu
提出日時 2020-10-04 18:34:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 780 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 168,276 KB
実行使用メモリ 37,220 KB
最終ジャッジ日時 2023-09-27 00:04:33
合計ジャッジ時間 7,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007

/*
srand((unsigned int)time(NULL));
for(int i=0;i<10;i++){
  cout<<rand()%6+1<<" ";
}
*/
/*
clock_t start,end;
start=clock();
end=clock();
double t=(double)(end-start)/CLOCKS_PER_SEC;
t<2.9;
*/

ll gcd(ll a,ll b){
  ll tmp=a%b;
  while(tmp!=0){
    a=b;
    b=tmp;
    tmp=a%b;
  }
  return b;
}

int main(){
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
    ll A,B;
    cin>>A>>B;
    vector<ll> ans;
    while(2*A<=B){
      ans.push_back(A);
      A+=A;
    }
    while(A<B){
      ll x=gcd(A,B-A);
      A+=x;
      ans.push_back(x);
    }
    cout<<ans.size()<<'\n';
    for(int j=0;j<ans.size();j++){
      cout<<ans[j]<<" ";
    }
    cout<<'\n';
  }
}
0