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