97k倍区间
⭐️难度:中等
 🌟考点:暴力,2017省赛
 📖

 📚
import java.util.Scanner;
public class  Main {
    static int N = 100010;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[N];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        // 预处理
        long[] s = new long [N];
        for (int i = 1; i <= n; i++) {
            s[i] = s[i -1] + a[i];
        }
        long[] cnt = new long[N];
        long res = 0;
        for (int i = 1; i <= n; i++) {
            if(s[i] % k == 0){
                res ++;
            }
            res = res + cnt[(int)(s[i] % k)];
            cnt[(int)(s[i] % k)] ++;
        }
        System.out.println(res);
    }
}
 
🍎笔记
 


















