首页 技术 正文
技术 2022年11月21日
0 收藏 319 点赞 4,419 浏览 867 个字

Description

Given a series of n numbers a1, a2, …, an, the partial sum of the numbers is defined as the sum of ai, ai+1, …, aj.

You are supposed to calculate how many partial sums of a given series of numbers could be divided evenly by a given number m.

Input

There are multiple test, each contains 2 lines.

The first line is 2 positive integers n (n <= 10000 ) and m (m <= 5000).

The second line contains n non-negative integers a1, a2, …, an. Numbers are separated by one or several spaces.

The input is ended by EOF.

Output

One test each line – the number of partial sums which could be divided by m.

Sample Input

5 4
1 2 3 4 5
6 7
9 8 7 6 5 4

Sample Output

2
3

Source

ZOJ Monthly March 2003

 #include <stdio.h>
int main(int argc, char *argv[])
{
int n,m;
int a[];
int sum[];
while( scanf("%d %d" ,&n ,&m)!=EOF ){
int ans=;
int ca[]={};
for(int i=; i<n; i++){
scanf("%d",&a[i]);
if(i==){
sum[i]=a[i]%m;
}else{
sum[i]=(sum[i-]+a[i])%m;
}
if(sum[i]%m==)
ans++;
ca[sum[i]]++;
}
for(int i=; i<m; i++)
ans+=ca[i]*(ca[i]-)/;
printf("%d\n",ans);
}
return ;
}
下一篇: Linux之FTP篇
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850