Help me in solving FLOW016 problem. What is wrong in my code ? Please help me figure it out

My issue

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int a,b,n,g,l;
	    cin>>a>>b;
	    if(a>b){
	        n=b;
	    }
	    else{
	        n=a;
	    }
	    for(int i=1; i<=n; i++){
	        if(a%i==0 && b%i==0){
	            g=i;
	        }
	    }
	    l=(a*b)/g;
	    cout<<g<<" "<<l<<endl;
	}
	return 0;
}

Problem Link: FLOW016 Problem - CodeChef

@subhodas666
Use long long int because when u will do a * b it will overflow the integer limit.