题目描述
package day;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class k倍区间 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String p[]=bufferedReader.readLine().split(" ");
int n=Integer.parseInt(p[0]);
int k=Integer.parseInt(p[1]);
long a[]=new long [n+1];
int b[]=new int [k+1];
b[0]=1;
for(int i=1;i<=n;i++){
a[i]=Integer.parseInt(bufferedReader.readLine());
a[i]+=a[i-1];
}
long res=0;
for (int i = 1; i <=n; i++) {
int c=(int) (a[i]%k);
res+=b[c];
b[c]++;
}
System.out.println(res);
}
}