AcWing 1230. K倍区间
原题链接
中等
作者:
是羊驼鸭
,
2021-05-01 18:49:15
,
所有人可见
,
阅读 280
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define inf 0x3f3f3f3f
#define int ll
using namespace std;
int read()
{
int res = 0,flag = 1;
char ch = getchar();
while(ch<'0' || ch>'9')
{
if(ch == '-') flag = -1;
ch = getchar();
}
while(ch>='0' && ch<='9')
{
res = (res<<3)+(res<<1)+(ch^48);//res*10+ch-'0';
ch = getchar();
}
return res*flag;
}
const int maxn = 1e5+5;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-8;
int n,k,res,a[maxn],sum[maxn],cnt[maxn];
signed main()
{
n = read(),k = read();
for(int i = 1;i <= n;i++)
{
a[i] = read(),sum[i] = (sum[i-1]+a[i])%k;
res += cnt[sum[i]];
cnt[sum[i]]++;
}
cout<<res+cnt[0]<<endl;
return 0;
}