My code is getting TLE even it passed all test cases at Leetcode

The code goes here:

#include<bits/stdc++.h>

using namespace std;

int main(){

long long n;

cin >> n;

for(long long i = 1; i < n; i++){

    cout << i << " ";

}

n = n - 1;

long long x = n * (n +1) * (-1);

cout << x/2 << "\n";

return 0;

}

Your code is already O(n). and is the optimal solution.
There must be test case issues with this question. I will confirm that

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.