Code working fine but test cases failing

#include
using namespace std;

void Game(int T){
for(int i=1;i<=T;i++){
int M;
cin>>M;
cout<<’ ';
int N;
cin>>N;
int m=1;
int n=2;
int summ=1;
int sumn=2;
M–;
N-=2;
while(summ<=M||sumn<=N){
m+=2;
n+=2;
M-=m;
N-=n;

       summ+=m;
       sumn+=n;

        if(M<=0){
            cout<<"Harshit";
			cout<<endl;
            break;
        }
        if(N<=0){
            cout<<"Aayush";
			cout<<endl;
            break;
        }
    
    }
}

}
int main(){
int T;
cin>>T;
if(T>=1 && T<=1000){
Game(T);
}
cout<<endl;
return 0;

}

Hello @sanyamvv33_df49c435732e7baf,

  • There is no need to print empty space after taking M as input.
  • sumn and summ are extra variables
  • Also your whille-break conditions are wrong it should be M<0 and N<0.

I think this will work,

#include<iostream>

using namespace std;

void Game(int T){

    for(int i=1;i<=T;i++){

        int M; cin>>M;

        int N; cin>>N;

        int m=1;

        int n=2;

        M--;

        N-=2;

        while(true){

            if(M<0){

                cout<<"Harshit";

                cout<<endl;

                break;

            }

            if(N<0){

                cout<<"Aayush";

                cout<<endl;

                break;

            }

            m+=2;

            n+=2;

            M-=m;

            N-=n;

        }

    }

}

int main(){

    int T;

    cin>>T;

   

    if(T>=1 && T<=1000){

        Game(T);

    }

    cout<<endl;

    return 0;

}

sir i am not familiar with this true thing inside while…
can you please explain it a bit like how and where to use it?

@sanyamvv33_df49c435732e7baf,
while(true) means your while loop is an infinite loop and will never break until your mentioned break condition becomes true.

You can check this if you want,

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.