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

TOJ 1721 Partial Sums的更多相关文章

  1. 51nod1161 Partial Sums

    开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...

  2. Non-negative Partial Sums(单调队列)

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  3. hdu 4193 Non-negative Partial Sums 单调队列。

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. 【计数】cf223C. Partial Sums

    考试时候遇到这种题只会找规律 You've got an array a, consisting of n integers. The array elements are indexed from ...

  5. CodeForces 223C Partial Sums 多次前缀和

    Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...

  6. 51 Nod 1161 Partial sums

    1161 Partial Sums  题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 给出一个数组A,经过一次 ...

  7. CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)

    ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...

  8. hdu 4193 - Non-negative Partial Sums(滚动数列)

    题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...

  9. hdu 4193 Non-negative Partial Sums

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4193 题意:给出一个n数列,要求把前i(1<=i<=n)个数移到剩余数列的后面形成新的数列 ...

随机推荐

  1. Arduino I2C + 数字式环境光传感器BH1750FVI

    BH1750FVI是日本罗姆(ROHM)半导体生产的数字式环境光传感IC.其主要特性有: I2C数字接口,支持速率最大400Kbps 输出量为光照度(Illuminance) 测量范围1~65535 ...

  2. easyui datagrid deleteRow(删除行)的BUG

    有时候想临时保存一些数据,等确定好后在批量一次提交,但EasyUI  datagrid 用的时候添加可以正常,如果从中间删除那行号就全乱了.导致删除的时候有可能删除上一行数据. function ad ...

  3. go语言 defer 你不知道的秘密!

    go 语言的defer功能强大,对于资源管理非常方便,但是如果没用好,也会有陷阱哦.我们先来看几个例子. 例一: defer 是先进后出 这个很自然,后面的语句会依赖前面的资源,因此如果先前面的资源先 ...

  4. ubuntu14.10,安装ksnapshot(截图软件)

    Linux:ubuntu14.10 ubuntu软件中心对它的描述:KSnapshot captures images of the screen.  It can capture the whole ...

  5. 【spring boot】FilterRegistrationBean介绍

    前言 以往的javaee配置过滤器是在web.xml中配置的,如下代码 <filter> <filter-name>TestFilter</filter-name> ...

  6. 编写可维护的Javascript纪要

    第一部分: 编程风格 在大型项目开发中,因为项目可读性规范性的需要(就像<编写可维护性的Javascript>一书作者Nicholas Zakas大神所说,他们团队所有成员写出的代码就像是 ...

  7. 牛客挑战赛30-T3 小G砍树

    link 题目大意: n个节点的带标号无根树.每次选择一个度数为1的节点并将它从树上移除.问总共有多少种不同的方式能将这棵树删到只剩 1 个点.两种方式不同当且仅当至少有一步被删除的节点不同. 题解: ...

  8. php 面试常问问题

    1.看看简历,会问一些过去做的项目的用户量.pv.吞吐量.相关难点和解决方法等2.数据库设计经验,为什么进行分表? 分库?一般多少数据量开始分表? 分库? 分库分表的目的? 什么是数据库垂直拆分? 水 ...

  9. [集合]线程安全的HashMap

    一.一般模式下线程安全的HashMap 默认情况常用的HashMap都是线程不安全的,在多线程的环境下使用,常常会造成不可预知的,莫名其妙的错误.那么,我们如何实现一个线程安全的HashMap呢?其中 ...

  10. Java ExecutorService 四种线程池

    1.new Thread的弊端 new Thead(new Runnable(){ @Override public void run() { // TODO Auto-generated metho ...