solution.cpp 459 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n, k, ans = 0, son[100000], sum[100000], b[100000] = {0};
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> son[i];
        if (i != 0)
            sum[i] = (sum[i - 1] + son[i]) % k;
        else
            sum[i] = son[i] % k;
        b[sum[i]]++;
        ans += b[sum[i]] - 1;
        if (sum[i] == 0)
            ans++;
    }
    cout << ans;
    return 0;
}