程序代码:
#include <stdio.h>
int goodSeries(int *a, int n, int s)
{
int i, len=0, b=-1, t=-1;
for (i=0; i<n-1; i++)
{
if (((a[i]+a[i+1])%s) == 0)
{
b = 2;
break;
}
}
if (s&1)
{
for (i=0; i<n; i++)
{
if ((a[i]%s) == 0)
{
len++;
}
else
{
if (len > b)
{
b = len;
}
len = 0;
}
}
if (len > b)
{
b = len;
}
}
else
{
for (i=0; i<n; i++)
{
if ((a[i]%s) == t)
{
len++;
}
else
{
if (len > b)
{
b = len;
}
t = -1;
len = 0;
if ((a[i]%s) == 0)
{
t = 0;
len++;
}
else if ((a[i]%s) == (s>>1))
{
t = s>>1;
len++;
}
}
}
if (len > b)
{
b = len;
}
}
return b;
}
void main()
{
int a[100000];
int n, k, i, b;
char tmp;
scanf("%d%d", &n, &k);
for (i=0; i<n; )
{
if (scanf("%d", a+i) == 0)
{
scanf("%c", &tmp);
continue;
}
i++;
}
b = goodSeries(a, n, k);
printf("%d\n", b);
}