Saleh127

CF 1364A

Jun 15th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define pi acos(-1)
  7. #define yes printf("YES\n");
  8. #define no printf("NO\n");
  9. int main()
  10. {
  11. Faster
  12. test
  13. {
  14. ll n,c=0,d,x,e=0,f=0,i,j,k=0,l=0;
  15. cin>>n>>x;
  16. ll a[n+5];
  17. for(i=0;i<n;i++)
  18. {
  19. cin>>a[i];
  20. c+=a[i];
  21. }
  22. if(c%x) cout<<n<<endl;
  23. else
  24. {
  25. for(i=0,j=n-1,l=1;i<n;i++,j--,l++)
  26. {
  27. e+=a[i];
  28. f+=a[j];
  29. if(e%x)
  30. {
  31. cout<<n-l<<endl;
  32. break;
  33. }
  34. if(f%x)
  35. {
  36. cout<<n-l<<endl;
  37. break;
  38. }
  39. }
  40. if(i==n) cout<<-1<<endl;
  41. }
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment