You have been given a number 'N'. Your task is to find the sum of all even numbers from 1 to 'N' (both inclusive).
Example :
Given 'N' : 6
Sum of all even numbers till 'N' will be : 2 + 4 + 6 = 12
Input Format :
The first line of the input contains an integer 'T', denoting the number of test cases.
The first line and the only line of each test case contains an integer 'N'.
Output Format :
For each test case, print a single integer representing the sum of even numbers till 'N'.
Print a single line for each test case.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= N <= 10^5
Time Limit: 1 sec
2
6
2
12
2
For test case 1 :
Sum of all even numbers till 6 will be : 2 + 4 + 6 = 12
For test case 2 :
Sum of all even numbers till 2 will be : 2
2
4
5
6
6
For test case 1 :
Sum of all even numbers till 4 will be : 2 + 4 = 6
For test case 2 :
Sum of all even numbers till 5 will be : 2 + 4 = 6
Try to traverse till N.
We can simply apply brute force and add numbers to a variable.
Here is the algorithm :
O(N), where ‘N’ is the given integer.
We traverse till ‘N’ and iterate ‘N/2’ times to add numbers. Hence, the overall complexity will be O(N/2) i.e. O(N).
O(1)
We use no extra space. Hence, the overall space complexity will be O(1).