Advertisement
mohammedehab2002

Untitled

Jun 13th, 2020
16,934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int t;
  6.     scanf("%d",&t);
  7.     while (t--)
  8.     {
  9.         int n,x,sum=0,l=-1,r;
  10.         scanf("%d%d",&n,&x);
  11.         for (int i=0;i<n;i++)
  12.         {
  13.             int a;
  14.             scanf("%d",&a);
  15.             if (a%x)
  16.             {
  17.                 if (l==-1)
  18.                 l=i;
  19.                 r=i;
  20.             }
  21.             sum+=a;
  22.         }
  23.         if (sum%x)
  24.         printf("%d\n",n);
  25.         else if (l==-1)
  26.         printf("-1\n");
  27.         else
  28.         printf("%d\n",n-min(l+1,n-r));
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement