GCD and LCM

Limits: 1s, 128 MB

You will be given two integers A, B. If A × B (product of A and B) is equal to LCM(A, B) then you have to print “yes” otherwise “no” without quotes.


This is a companion discussion topic for the original entry at https://toph.co/p/gcd-and-lcm
#include<iostream>
using namespace std;

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int main()
{
    int n;
    cin >> n;
    int a, b;
    for(int i=1; i<=n; i++)
    {
        cin >> a >> b;
        if(gcd(a, b) == 1)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}

What’s the problem with my code?

You are using int a, b. You need a larger type here. Because the numbers in the input can be as large as 1018.

#include
using namespace std;
int main()
{
int num,i;
long long a,b,m,n,rem,div;
cin>>num;
for(i=0;i<num;i++)
{
cin>>a>>b;
m=a;
n=b;
while(n!=0)
{
rem=m%n;
m=n;
n=rem;
}
div=(ab)/m;
if(a
b==div)
{
cout<<“yes”<<endl;
}
else
cout<<“no”<<endl;
}
}
what is the problem in this code??