1009: Interval Value of QAQ [Thinking]
Time Limit: 1 Sec Memory Limit: 128 MBenter
Enter an integer T on the first lineT , representing a TT group test data.
Each set of data occupies two lines, the first line input an integer NN , representing the number of elements in the sequence.
Note: 1 < = T<=10000,1<=N<=1000001<=T<=10000,1<=N<=100000。
Each set of data occupies two lines, the first line input an integer NN , representing the number of elements in the sequence.
Note: 1 < = T<=10000,1<=N<=1000001<=T<=10000,1<=N<=100000。
output
For each set of test data, output the sum of all subinterval values of the sequence.
sample input
3
1
2
99
Sample output
1
0
2500
When N is an even number, the result is zero; when N is an odd number, the result is 1+3+5+...+N. That is, the first item is 1, the tolerance is 2, and the arithmetic difference of (N+1)/2 items in total sequence.
The formula is sorted into (N+1)*(N+1)/4
AC:
#include<iostream>
using namespace std;
int main(){
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
if(N&1)
cout<<(N+1)*(N+1)/4<<endl;
else
cout<<0<<endl;
}
return 0;
}