Getting timedout error while calculating the value of sigma notation sigma(i=1 to k)((-1)^i+1)(i)(i+1) for very long values example :10^8 .Can any one guide me where I am doing wrong
import java.io.*;
import java.util.*;
public class TestClass {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wr = new PrintWriter(System.out);
int T = Integer.parseInt(br.readLine().trim());
for(int t_i=0; t_i<T; t_i++)
{
int params1 = Integer.parseInt(br.readLine().trim());
long out_ = maxValueX(params1);
System.out.println(out_);
System.out.println("");
}
wr.close();
br.close();
}
static long maxValueX(long params1){
long sum=0;
for(long i=1;i<=params1;i++){
sum=(long)Math.pow(-1,i+1)*i*(i+1)+sum;
}
return sum;
}
}