GCD and LCM

#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;
} 

3.89
9
Tara Lehman 105 points

                                    function gcd(a, b)
    if b = 0
        return a
    else
        return gcd(b, a mod b)

3.89 (9 Votes)
0
3
1

                                    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)]
}

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
lcm in terms of gcd find lcm from gcd If gcd(a,b)&lt;a, then lcm(a,b)&lt;a. gcd(a, b) &lt; a gcd lcm sample problems in c gcd lcm sample problems gcd lcm problem gcd lcm algorithm how to find gcd and lcm of two numbers how to find gcd and lcm gcd(0, 0) lcm using built in gcd gcd and lcm codechef best algorithm to find GCD how to get lcm from gcd what is gcd mean gcd (a, b) * lcm (a, b) lcm(gcd(a, b), gcd(b, d)) lcm without GCD lcm gcd in c programming lcm using gcd in c++ properties of lcm and gcd lcm formula using gcd gcd (0,0) gcd and lcm in c++ relation between gcd and lcm gcd and lcm calculator how to calculate gcd and lcm c program for lcm and gcd gcd using euclid's algorithm gcd and lcm of three numbers what does gcd mean gcd c gcd(0, 5) lcm without using gcd gcd(a-b,b) gcd and lcm in c geeksforgeeks lcm gcd i c what is the algorithm for gcd gcd lcm stands for gcd lcm reference what is gcd (a,b) gcd(a, m)gcd(a, n) = agcd(m, n) gcd and lcm relationship graph of gcd function codechef lcm and gcd gcd algorithm step by step gcd and lcm program in c gcd problem example gcd(36,0) gcd best algorithm gcd lcm in c gcd cp algorithms gcd algorithm runt gcd lcm formula lcm from gcd gcd in data structure gcd algorithm complexity gcd and lcm formula what is gcd and lcm lcm using gcd gcd and lcm in discrete mathematics lcm and gcd gfg gcd lcm formula for programming lcm gcd lcm equation gcd gcd and lcm of two numbers gcd and lcm gfg gcd(a,b) = a lcm and gcd gcd(a,b) = 1 gcd(a+1,b) gcd(a,b) = gcd(b,a) gcd equation with lcm gcd(a,b)|c math algorithm for gcd gcd euclidean algorithm explain all algorithm to find GCD gcd vs lcm lcm to gcd The gcd(m,n) gcd(a, a+b) gcd(k, k+a) gcd(a b)=gcd(a a+b) gcd algorithm array gcd(a^n, b)= gcd(a,b) what is gcd in math gcd implementation gcd finding algorithm gcd(a,b)=1 gcd(a,a) gcd algorithm gfg what is gcd(a,b) gcd(0,0) gcd(a,b) gcd using euclidean algorithm gcd definition gcd example GCD program explain gcd function gcd cp al algorithm of gcd in c finding gcd algorithm GCD algorithme C euclid's algorithm gcd Implement Euclid's algorithm to compute the GCD gcd function java dgc euclidean algorithm gcd java program Euclidean algorithm euklides algorithm gcd and lcm gcd of two numbers euclid gcd and lcm algorithm euclidean theorem for gcd euclid's gcd algorithm basic and euclidean algorithm euclidean algorithm for finding the gcd of two numbers fast euclidean algorithm Write a program to find out GCD (greatest common divisor) using the following three algorithms. a) Euclid&rsquo;s algorithm basic and euclidean algorithm for cryptography basic and euclidean lgorithm gcd-greedy algorithm use euclid's 2 algorithm algorithm using gcd pesudo code for eulars greatest commmon divisor euclidean theorem gcd basic euclid algorithm find gcd of two numbers using euclidean algorithm prove euclid's algorithm gcf algorithm algorithms to find gcd euclid's algorithm using random integers euclidean algorithm cryptography gcd calculation algorithm gcd of two numbers using euclid algorithm Explanation: Solving quadratic equations is not an application of Euclid&rsquo;s algorithm whereas the rest of the options are mathematical applications of Euclid&rsquo;s algorithm. greatest common divisor algorithm euclidean algo to find GCD euclidean algorithm for gcd example how to prove euclid's algorithm euler's algorithm for gcd euler gcd function euclidean algorithm java wikipedia maximum common divisor algorithm eucid formula se Euclid&rsquo;s algorithm meanig eluclid algorithm euclid gcd algorithm gcd euclidean algorithm best gcd algorithm euclidean algorithm. euclid&rsquo;s algorithm max number of divisions Euklidean algorithm for determining the greatest common divisor gcd(a, b): while b != 0: a, b = b, a % b return a binary gcd algorithm compared to euclid's theorem euclidean algorithm for gcd find gcd algorithm euclidean algorithm algorithm for gcd euclid's algorithm Euclids GCD algorithm euclidean algorithm for gcd of two numbers eudiam algorithm gcd wikipedia euclidean algorithm euclid algorithm for gcd gcd algorithm euclidean algorith to find gcd euclid algorithm euclidean algorithm gcd
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source