Help me in solving ODDSUM problem

My issue

Why my code is giving TLE ?
My Code:
include <bits/stdc++.h>
define ll long long
using namespace std;
int main() {
// your code goes here
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t;
cin >> t;
while(t–)
{
ll n;
cin>>n;
if(n==1)
{
cout<<1<<endl;
continue;
}
ll ans=1;
n-=2;
ans+=(n*(n+1));
cout<<ans<<endl;
}
return 0;
}

My code

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	ll t;
	cin >> t;
	while(t--)
	{
	    ll n;
        cin>>n;
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        ll ans=1;
        n-=2;
        ans+=(n*(n+1));
        cout<<ans<<endl;
	}
	return 0;
}

Learning course: 1600 to 1800 difficulty problems
Problem Link: Odd Sum Practice Problem in 1600 to 1800 difficulty problems - CodeChef

@alokbarnwal54
plzz refer my c++ code

#include <bits/stdc++.h>
#include <ios>
using namespace std;

int main() {
	int T;
	cin >> T;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	while(T--){
	    long long n;
	    cin >> n;
	    cout << (n-1)*(n-2)+1 << "\n";
	}
	return 0;
}