#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5;
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[65], b[100000], l = 0;
  long long x = 1;
  a[0] = 0;
  for (int i = int(1); i <= int(64); i++) {
    x = x * 2;
    a[i] = x - 1;
  }
  x = 0;
  long long z = 0, q = 3;
  while (n > 0) {
    z = x * m + 1;
    long long p = upper_bound(a, a + 64, n) - a;
    n = n - a[p - 1];
    for (int i = int(1); i <= int(p - 1); i++) b[l] = z, l++;
    x++;
  }
  cout << l << '\n';
  for (int i = int(0); i <= int(l - 1); i++) cout << b[i] << " ";
}
