Source Code
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;

int main() {
//   #ifndef ONLINE_JUDGE
// 	 freopen("in.txt", "r", stdin);
//   #endif
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  ll x;   cin >> x;
  vector<int> v;
  for(int i = 1; i < 2e6; i++){
    if((i * (i + 1)) / 2 == x){
      v.push_back(i); break;
    }
    else if((i * (i + 1)) / 2 < x)
      v.push_back(i);
    else{
      v.push_back(i); break;
    }
  }
  int size = int(v.size()), num = ((v[size - 1] * (v[size - 1] + 1)) / 2) - x;
  if(num == 0)  
    cout << size << '\n';
  else
    cout << size - 1 << '\n';
  for(int i = 0; i < size; i++)
    if(v[i] != num)
      cout << v[i] << ' ';
  
  
  
  return 0;
}
Copy
Want More! Ammar_Lahloh
GNU G++17
111 ms
23.7 MB
Wrong Answer