Whats wrong with the code for testcases it is giving TLE

send the link of question from hacker blocks or
tell the exact name of problem

For a positive integer ‘n’ let’s define a function: f(n) = - 1 + 2 - 3 + … + (( - 1)n)*n Your task is to calculate f(n) for a given integer n. Input Format The first line contains an integer T, the no. of test cases. The next T lines contain a positive integer denoting the values of ‘n’ for f(n). Please note the value of N is large as given in constraints. Constraints 1 ≤ T ≤ 1018 1 ≤ n ≤ 1018 Output Format Print the values of f(n) in separated lines. Sample Input 2 5 4 Sample Output -3 2 Explanation Use mathematical series function to solve this problem.

https://hack.codingblocks.com/app/practice/3/1001/problem

try to make formula for solving this
because of contraints

1 ≤ T ≤ 1018
1 ≤ n ≤ 1018

if you use brute force or try to add one by one the it will definitely give TLE

in one sec you can do at max 10^8-10^9 operations

look at sequence carefully
-1 +2 -3 +4…
sum of consecutive nos is 1

now if n is even it will go one and total sum=n/2;

but if n is odd
(-1+ 2 -3 +4 …)-n
total sum = ( (n-1)/2 -n )

https://ide.codingblocks.com/s/259409 is this logic correct

:+1:

if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course