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 ;
}

最新文章

  1. supervisor-1:基础篇
  2. Haskell Platform (windows)
  3. Convert Sorted Array to Binary Search Tree || LeetCode
  4. UITableView中Cell和section的插入与删除
  5. 整站HTTPS后的跨域请求 CORS是否还有效?
  6. HL AsySocket 服务开发框架 - 业务逻辑层
  7. C# virtual和abstract的
  8. javascript 数组排序之 sort()
  9. 获取设备上全部系统app信息
  10. Android 获取JSP或ASP的sessionId(Cookie)
  11. 学习笔记-[Maven实战]-第三章:Maven使用入门(2)
  12. Html.RenderPartial与Html.RenderAction区别(转)
  13. preventDefault() 方法 取消掉与事件关联的默认动作
  14. SQL__用命令删除定期的备份数据库文件
  15. swift3.0 底部弹出菜单 UIAlertController的使用
  16. 用Markdown写微信公众号文章
  17. 【转载】Nginx + Tomcat 实现反向代理
  18. python写csv文件
  19. Linux学习必备
  20. MySQL将DESC等关键字作为列名表名的处理方式

热门文章

  1. tomcat的内存配置,关于-Xms -Xmx -XX:PermSize -XX:MaxPermSize的理解和区别
  2. Python中多使用迭代器
  3. Graphic 完成文字缩放
  4. Django中使用后台网站模板
  5. Topshelf + Quartz2.5 创建基于windows服务
  6. NSData 数据
  7. atp
  8. app.use和app.get的区别及解析
  9. win 10 问题
  10. Apache htaccess 设置....