Help on question

void solve()
{
ll n,k;
cin>>n>>k;
ll left = 1, right = 1e9;
if(k%2==0){
int ok = n;
while(ok>0){
cout << left << " " << right << " ";
left++;
right–;
ok-=2;
}
}
else{
int ok = n;
while(ok>0){
for(int i=0;i<(k/2)+1;i++){
cout << left << " ";
left++;
}
for(int i=0;i<(k/2);i++){
cout << right << " ";
right–;
}
left += (k/2)-1;
right-=3+(k/2-1);
ok-=k;
}
}
cout << endl;
}

int main()
{
int test=1;
cin>>test;
while(test–)
{
solve();
}
}

This is the solution for AVERAGE CHEF question. Can anyone tell what this part is exactly doing

int ok = n;
		while(ok>0){
			for(int i=0;i<(k/2)+1;i++){
				cout << left << " ";
				left++;
			}
			for(int i=0;i<(k/2);i++){
				cout << right << " ";
				right--;
			}
			left += (k/2)-1;
			right-=3+(k/2-1);
			ok-=k;
		}

I tried to analyze it but I cant figure out whats wrong?