fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. //#define push_back pb;
  5. //#define make_pair mp;
  6. #define lp(i,start , end) for(int i = start ; i<end ; ++i)
  7. #define Rlp(i,start , end) for(int i = start ; i>end ; --i)
  8. #define all(v) ((v).begin(),(v).end())
  9. #define sz(v) (int)((v).size())
  10. #define clr(v,d) memset(v , d , sizeof(v))
  11. typedef long long ll;
  12. typedef vector<int> vi;
  13. typedef vector <ll> vll;
  14. typedef vector<vector<int> > adj;
  15. typedef pair<int ,int> pii;
  16.  
  17.  
  18. const double EPS =1e-7;
  19. const int OO = 1e6;
  20. bool sortpair( const pair<int , int> & x, const pair<int , int> & y)
  21. {
  22.  
  23. return x.first != y.first ? x.first < y.first : x.second > y.second ;
  24.  
  25.  
  26. }
  27. int dcomp(double x , double y)
  28. {
  29. return fabs(x-y) <= EPS? 0: x>y?1:-1;
  30. }
  31. //int arr[22];
  32. int main() {
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(NULL);
  35. cout.tie(NULL);
  36.  
  37. int n , k; cin >> n >> k;
  38. int ans = (n + 2* k )/ (2*k +1) ;
  39.  
  40. cout<<ans <<endl;
  41. int j = 1;
  42. lp(i,1, ans+1){
  43. if(j* k +i > n) cout<<n;
  44. else
  45. cout<<j*k+i<<" ";
  46. j+=2;
  47. }
  48. cout<<endl;
  49. return 0;
  50. }
Success #stdin #stdout 0s 15232KB
stdin
7 2
stdout
2
3 7