Answers for "GCD and LCM"

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
2

gcd algorithm

function gcd(a, b)
    if b = 0
        return a
    else
        return gcd(b, a mod b)
Posted by: Guest on September-22-2020
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 "Javascript"

Browse Popular Code Answers by Language