-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
59 lines (58 loc) · 1.2 KB
/
A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
int main()
{
long long int t,n,x,ara[100005],i,a,b,p,sum=0,m;
scanf("%lld",&t);
while(t--)
{
p=0;
m=0;
scanf("%lld%lld",&n,&x);
for(i=0;i<n;i++)
{
scanf("%lld",&ara[i]);
}
sum=0;
for(i=0;i<n;i++)
sum=sum+ara[i];
if(sum%x!=0)
printf("%lld\n",n);
else
{
for(i=0;i<n;i++)
{
if(ara[i]%x!=0)
{
p=1;
break;
}
}
if(p==0)
printf("-1\n");
else
{
for(i=0;i<n;i++)
{
if(ara[i]%x!=0)
{
a=i+1;
break;
}
}
for(i=n-1;i>a-1;i--)
{
if(ara[i]%x!=0)
{
b=n-i;
break;
}
}
if(a<=b)
printf("%lld\n",n-a);
else
printf("%lld\n",n-b);
}
}
}
return 0;
}