Answers for "GCD and LCM codechef solution"

1

GCD and LCM codechef solution

#include<stdio.h>


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


int main()
{
		
		long long t;
		scanf("%lld",&t);
		
		while(t--)
		{
			long long a,b,k;
			
			scanf("%lld%lld",&a,&b);
			
			k=gcd(a,b);
			
			printf("%lld %lld\n",k,(a*b)/k);
			
		}
		
		return 0;
}
Posted by: Guest on May-25-2021
0

GCD and LCM

function gcd(a, b) {
    let r;
    while (r!=0) {
        r = a % b;
        a = b;
        b = r
    }
    return a;
}

function lcm(a, b) {
    return Math.abs(a*b) / gcd(a,b);
}

function solution(n, m) {
    return [gcd(n,m), lcm(n,m)]
}
Posted by: Guest on July-10-2021

Code answers related to "GCD and LCM codechef solution"

Browse Popular Code Answers by Language