#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 50;
const int oo = 1e9;
const int mod = 1e9 + 7;
long long a[N];
int main() {
  long long n, m;
  cin >> n >> m;
  long long c = 1;
  int cur = 0;
  for (int i = 30; i; i--) {
    while (n >= (1 << i) - 1) {
      for (int j = 1; j <= i; j++) a[cur++] = c;
      c += m;
      n -= (1 << i) - 1;
    }
  }
  cout << cur << endl;
  for (int i = 0; i < cur; i++) cout << a[i] << ' ';
  puts("");
}
