古墓丽影

Problem B.古墓丽影

Rise of The Tomb Raider

 

Input file

lara.in

Output file

lara.out

Time limit

1 sec

Memory limit

128 mb

 

   劳拉是Liang的女神,Liang常常和她去一些古墓探险。

在一个希腊遗迹中,劳拉女神必须利用希腊火打开出去的大门,可是想打开存储希腊火的大门,要解决希腊哲人出的难题。

n 个正整数排成一行。你的目的是要从中取出一个或连续的若干个数,使它们的和能够被 k 整除。

 

例如,有个正整数,它们依次为 1; 2; 6; 3; 7; 4。若 k = 3,则你可以取出 1; 2; 6,或者 2; 6; 3; 7,也可以仅仅取出一个或者使你所取的数之和能被整除。当然,满足要求的取法不止以上这种。事实上,一共有种取法满足要求。

 

给定 n  k,以及这 n 个数。你的任务就是确定从这 n 个数中取出其中一个数或者若干连续的数,使它们的和能被 k 整除有多少方法。记 Ha = 1234567,由于取法可能很多,因此你只需要输出它 mod Ha 的值即可

Liang和劳拉的事就交给你们了

 

 

 

Input

 

第一行为两个整数 n; k。以下 n 行每行一个正整数,描述这个序列。

 

Output

 

 

输出一个整数,为答案 mod Ha 的结果。

 

 

 

 

 

 

Examples

 

lara.in

lara.out

6 3

 

1

 

2

 

6

 

3

 

7

 

4

 

7

 

Hint

 

对于 30% 的数据,有 1<=n<=1000

 

对于 100% 的数据,有 1<=n<=500000; 1<=k<=100000

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 typedef long long LL;
 8 const int ha=1234567;
 9 const int maxk=100005,maxn=500005;
10 int n,k;
11 LL sum[maxn];
12 int cnt[maxk];
13 
14 inline LL scan()
15 {
16     LL res=0;
17     char ch=getchar();
18     while(ch<'0'||ch>'9') ch=getchar();
19     while(ch>='0'&&ch<='9')
20     {
21         res=res*10+ch-'0';
22         ch=getchar();
23     }
24     return res;
25 }
26 
27 int main()
28 {
29     #ifndef ONLINE_JUDGE
30         freopen("lara.in","r",stdin);
31         freopen("lara.out","w",stdout);
32     #endif
33     scanf("%d %d",&n,&k);
34     for(int i=1;i<=n;++i)
35     {
36         sum[i]=scan();
37         sum[i]=(sum[i]+sum[i-1])%k;
38         cnt[sum[i]]++;
39     }
40     LL ans=0;
41     ans=cnt[0]+cnt[0]*(cnt[0]-1)/2;
42     for(int i=1;i<k;++i)
43     {
44         ans+=cnt[i]*(cnt[i]-1)/2;
45         ans%=ha;
46     }
47     cout<<ans;
48     return 0;
49 }
View Code

 

posted @ 2016-11-13 22:12  cnblogsLSY  阅读(95)  评论(0)    收藏  举报