link to the problem : Contest Page | CodeChef

I was doing this problem with a logic that i can take 1 2 2 3 as initial value in an vector **vec** not taking consideration of n=1 and n=2 (i put it in if-else if cases )

then initially sum = 8 and when my for loop reaches last value i just subtract total sum to **n** value. I don’t know where i am getting wrong.

```
void solve()
{
int n, sum=8;
cin >> n;
vector<int> vec={1,2,2,3};
if (n == 1)
cout << "1 1" << endl;
else if (n == 2)
cout << "1 1 2" << endl;
else
{
for (int i = 4; i < n+1; i++)
{
if(i==n)
{
int ttl = pow(2, n) - sum;
vec.push_back(ttl);
break;
}
vec.push_back(i + 1);
sum+=vec[i];
}
for (auto v : vec)
{
cout << v << " ";
}
cout << endl;
}
}
```