This Code gives correct output -->
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n == 1){
cout<<0<<endl;
continue;
}
ll ans = 0;
for(int i = 1; i <= n/2; i++){
ans += (i*1LL*i);
// Gives WA when write
// ans += (i*i*1LL); Is order of 1LL matters ??
}
cout<<ans*8<<endl;
}
return 0;
}
But this gives WA (Can check for sample test Cases)
sample test Case:
3
1
5
499993
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n == 1){
cout<<0<<endl;
continue;
}
ll ans = 0;
for(int i = 1; i <= n/2; i++){
ans += (8*i*i*1LL);
}
cout<<ans<<endl;
}
return 0;
}
Am unable to figure out the mistake.
Can someone help me , It will be appreciated.Thank You.