Codeforces 1364A. XXXXX Solution
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n,i,sum=0,m1=-1,m2,x,a;
- cin>>n>>x;
- for(i=0; i<n; i++)
- {
- cin>>a;
- sum+=a;
- if(a%x)
- {
- if(m1==-1)
- m1=i;
- else
- m2=i;
- }
- }
- if(sum%x)
- cout<<n<<endl;
- else if(m1==-1)
- cout<<"-1"<<endl;
- else
- cout<<n-min(m1+1,n-m2)<<endl;
- }
- }
No comments