Help me in solving BMCC18 problem

My issue

My code

// Update the code below to solve the problem

#include <bits/stdc++.h>
using namespace std;

int main() 
{
	int t;
    cin >> t;
	
	while(t--)
	{
	    int N, M,i;
	    cin >> N >> M;
	    for(i=min(N,M);i>=1;i--)
	    {
	        if((N*M)%(i*i)==0)
	        break;
	    }
	    cout<<(N*M)/(i*i)<<endl;
	}
}

Learning course: Solve Programming problems using C++
Problem Link: CodeChef: Practical coding for everyone

@hkbharti77
u have done logical mistake
the condition u find gcd is not right;
u have to do like this

#include <bits/stdc++.h>
using namespace std;

int main() 
{
	int t;
    cin >> t;
	
	while(t--)
	{
	    int N, M,i;
	    cin >> N >> M;
	    for(i=min(N,M);i>=1;i--)
	    {
	        if(N%i==0&&M%i==0)
	        break;
	    }
	    cout<<(N*M)/(i*i)<<endl;
	}
}