fork(2) download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int main() {
  6. int sum, lim, low_bit, n=0, a[100005];
  7. scanf("%d%d", &sum, &lim);
  8. for(int i=lim; i>=1; i--) {
  9. low_bit = i & -i;
  10. if(sum>=low_bit) a[n]=i, n++, sum-=low_bit;
  11. if(sum==0) break;
  12. }
  13. if(sum>0) printf("-1");
  14. else {
  15. printf("%d\n", n);
  16. while(n--) printf("%d ", a[n]);
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 3612KB
stdin
5 1
stdout
-1