question-FLOW016 ,the code is giving right answer for every test case but still it says wrong answer

#include
using namespace std;

int main() {

int t;
cin>>t;
while(t--){
    
    int num1,num2;
    cin>>num1>>num2;
    int a= max(num1,num2),b=min(num1,num2),r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    cout<<b<<" "<<((num1*num2)/b)<<endl;
}	
return 0;

}

link to problem: Contest Page | CodeChef

Input: A (=num1), B (=num2) ≤ 10⁶

the error: cout<<b<<" "<<((num1*num2)/b)<<endl;
num1 * num2 ≤ 10¹²

if both num1 and num2 are ints, you may cause an integer-overflow. Therefore you should use long long for at least one of them.

1 Like

yeah i see,thank you very much for the help^_^

1 Like