結果

問題 No.1243 約数加算
ユーザー tnakao0123tnakao0123
提出日時 2020-10-03 02:50:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,258 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 90,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 04:34:42
合計ジャッジ時間 1,595 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 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,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1243.cc:  No.1243 約数加算 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_K = 200;
const int BN = 60;

/* typedef */

typedef long long ll;

/* global variables */

ll xs[MAX_K];

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m > 0, n > 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    ll a, b;
    scanf("%lld%lld", &a, &b);

    int k = 0;
    for (int i = 0; i < BN; i++) {
      ll bi = 1LL << i;
      if (a % (bi << 1) != 0 && a + bi <= b)
	xs[k++] = bi, a += bi;
    }
    for (int i = BN - 1; i >= 0; i--) {
      ll bi = 1LL << i;
      if (a + bi <= b)
	xs[k++] = bi, a += bi;
    }

    printf("%d\n", k);
    for (int i = 0; i < k; i++) {
      printf("%lld", xs[i]);
      putchar(i + 1 < k ? ' ' : '\n');
    }
  }
  return 0;
}
0