This is a problem of finding lcm as well as gcd..... it works just fine in my compiler but when I submit .... I get a WA ... help

https://www.codechef.com/problems/FLOW016

#include <iostream>

int gcd(int a, int b)
      {
       if(a==0)
             return b;
        return gcd(b%a,a);
      }
  int lcm(int a, int b)
{
  return (a*b)/gcd(a,b);
}
  int main()
{
int t;
std::cin >> t;
while(t--)
{
   int a,b;
   std::cin >> a >> b;

   std::cout << gcd(a,b) << " ";
   std::cout << lcm(a,b) << " ";
   std::cout << '\n';
}

return 0;

}

In the LCM function the LCM of a and b may exceed range of int as it is 10^9 and the range of A and B is 10^6 so if the no. are prime is may have 12 digits

1 Like

long long int is good for your health…!

1 Like

thank you very much

thanks very much

Its integer overflow possibly, better if you use long long

Yes ! That was the mistake… and I have resolved it. Thanks