思路:把x进行分解,构造出可满足的 2^k-1个集合,每个集合互不干扰(+d+1),直至x=0
#include<bits/stdc++.h>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int N=1e5+50;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
vector <ll> ans;
int main(void){
ll x,d;
cin >>x >> d;
ll now=1;
for(int i=31;i>=1;i--){
while(x>=(1<<i)-1){//显然while次数很少
for(int j=1;j<=i;j++) ans.push_back(now);
x-=(1<<i)-1;
now+=d+1;
}
}
// cout <<"x="<<x<<endl;
cout << ans.size()<<endl;
for(int i=0;i<(int)ans.size();++i)
printf("%lld ",ans[i]);
return 0;
}
/**************
**************/