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

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5. int t;
    6. cin>>t;
    7. while(t--)
    8. {
    9. int n,i,sum=0,m1=-1,m2,x,a;
    10. cin>>n>>x;
    11. for(i=0; i<n; i++)
    12. {
    13. cin>>a;
    14. sum+=a;
    15. if(a%x)
    16. {
    17. if(m1==-1)
    18. m1=i;
    19. else
    20. m2=i;
    21. }
    22. }
    23.  
    24. if(sum%x)
    25. cout<<n<<endl;
    26. else if(m1==-1)
    27. cout<<"-1"<<endl;
    28. else
    29.  
    30. cout<<n-min(m1+1,n-m2)<<endl;
    31. }
    32. }
    33.  

    No comments

    Most View Post

    Recent post

    Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.