Doubt in SUBMIMX

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. /
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in=new Scanner(System.in);
int T=in.nextInt();
ArrayList l1=new ArrayList<>();
int N,M,gap,zero,zpg,sum=0,rem=0;
//zpg means zeros per gap (the expected value)
while(T>0)
{
T–;
N=in.nextInt();
M=in.nextInt();
gap=M+1;
zero=N-M;
zpg=zero/gap;
rem=zero-zpg
gap;
sum=zpg*(zpg+1)/2*(gap-rem) +(zpg+1)(zpg+2)/2rem;
System.out.println(sum);

	}
}

}

// I have written this code in java for the problem → Substring Minimum Function.(SUBMIMX)
// This code when submitted showed Wrong Answer
// Can anyone please help me out where am i going wrong