#include<stdio.h>
int main()
{
long long num[100000], t, p, number, lucky, max = -1, a, sum = 0, range = 1, m = 0;
scanf("%lld", &t);
for (p = 0; p < t; p++)
{
scanf("%lld %lld", &number, &lucky);
for (a = 0; a < number; a++)
scanf("%lld", &num[a]);
max = -1;
range = 1;
for (a = 0; range <= number;)
{
for (m = 0; m < range && a + range - 1 < number; m++)
sum += num[a + m];
if (sum % lucky == 0 && sum != 0)
{
max = range;
a = number - range;
}
m = 0;
a++;
sum = 0;
if (a == number + 1 - range)
{
range++;
a = 0;
}
}
printf("%lld\n", max);
}
return 0;
}
想不到什么更好的方法了。。有大佬可以赐教吗
全部评论
(0) 回帖