gcd and lcm

Solutions on MaxInterview for gcd and lcm by the best coders in the world

showing results for - "gcd and lcm"
Diego
04 May 2020
1#include<stdio.h>
2
3
4long long gcd(long long a , long long b)
5{
6		if(a==0)
7			return b;
8		
9		return gcd(b%a , a);
10	
11}
12
13
14int main()
15{
16		
17		long long t;
18		scanf("%lld",&t);
19		
20		while(t--)
21		{
22			long long a,b,k;
23			
24			scanf("%lld%lld",&a,&b);
25			
26			k=gcd(a,b);
27			
28			printf("%lld %lld\n",k,(a*b)/k);
29			
30		}
31		
32		return 0;
33} 
34
Timmy
16 Apr 2018
1function gcd(a, b)
2    if b = 0
3        return a
4    else
5        return gcd(b, a mod b)
6
Valentina
22 Sep 2020
1function gcd(a, b) {
2    let r;
3    while (r!=0) {
4        r = a % b;
5        a = b;
6        b = r
7    }
8    return a;
9}
10
11function lcm(a, b) {
12    return Math.abs(a*b) / gcd(a,b);
13}
14
15function solution(n, m) {
16    return [gcd(n,m), lcm(n,m)]
17}
18
19
queries leading to this page
gcd lcm problemgcd 280 2c0 29gcd and lcm codegcd algorithm cgcd and lcm calculatoreuclidean algorithm gcd java programeuclidean algorithm for gcdgcd lcmgcd 28a 2cb 29 3d1gcd of two numbers euclidalgorithms to find gcdgcd solutionlcm using built in gcdlcm formula using gcdgcd and lcm in c 2b 2bmath algorithm for gcddgc euclidean algorithmeuklides algorithmgcd calculation algorithmcodechef lcm and gcdgcd 28a 5en 2c b 29 3d gcd 28a 2cb 29lcm equation gcdgcd 28a 2b1 2cb 29gcd finding algorithmgcd lcm sample problemsgcd and lcm formulagcd lcm algorithmgcd and lcm gfg practicefinding gcd algorithmbasic and euclidean lgorithmwhat is gcd 28a 2cb 29greatest common divisor algorithmeluclid algorithmgcd lcm in cc algorithm to get gcdeuclidean algorithm java wikipedialcm gcd i ceuclidean algorith to find gcdlcm without using gcdgcd definitiongcd best algorithmwhat is gcd 28a 2cb 29gcf algorithmgcd algorithm runtgcd 280 2c0 29gcd of two numbers using euclid algorithmwhat is gcd in mathgcd lcm in cbinary gcd algorithm compared to euclid 27s theoremlcm using gcdalgorithm for finding the gcdgcd and lcm function in c 2b 2bfind gcd of two numbers using euclidean algorithmmaximum common divisor algorithmgcd and lcm algorithmhow to calculate gcd and lcmpesudo code for eulars greatest commmon divisorgcd 28a 2cb 29 3dgcd 28b 2ca 29gcd lcm c 2b 2bgcd 28a 2c m 29gcd 28a 2c n 29 3d agcd 28m 2c n 29gcd 28a 2cb 29 3dahow to find lcm gcd in c 2b 2blcm using gcd in c 2b 2bgcd examplegraph of gcd functionwhat does gcd meangcd cp algcd is hcf or lcmeuclidean algorithmgcd and lcm codechef solutionproperties of lcm and gcdgcd and lcm program in cgcd 28a b 2cb 29fast euclidean algorithmgcd lcm formulagcd 28a 2ca 29prove euclid 27s algorithmlcm gcdgcd 28a 2c b 29 3d 1gcd implementationgcd euclidean algorithm explainbasic euclid algorithmalgorithm of gcdlcm gcd equationgcd 26 lcmrelation between gcd and lcmgcd and lcm in c geeksforgeekseuclid 27s gcd algorithmgcd and lcm in discrete mathematicsc program to find lcm and gcdgcd and lcm relationshipeuclid e2 80 99s algorithm meaniggcd algorithm complexityeuler gcd function1 lcm 28a 2cb 29 2a gcd 28a 2cb 29what is gcd meangcd euclidean algorithmbinary gcd algorithmwhat is lcm and gcdalgorithm using gcdgcd 28a 2cb 29 7ccgcd 28k 2c k 2ba 29gcd and lcmeuclid gcd algorithmwhich of the following is not another name for gcd 28greatest common divisor 29 3f hcf gcm gcf lcmbest algorithm to find gcdwhat is gcd and lcmeuclid e2 80 99s algorithm max number of divisionsgcd algorithm gfggcd and lcm codeforce solutionlcm and gcd gfgwikipedia euclidean algorithmis lcm and gcd sameeuclidean theorem gcdgcd 28 29all algorithm to find gcdgcd cp algorithmsgcd functiongcd 280 2c 0 29 euclidean algorithmgcd 28a 2c b 29 2a lcm 28a 2c b 29gcd and lcm gfglcm 28gcd 28a 2c b 29 2c gcd 28b 2c d 29 29gcd and lcm codecheflcm into gcdhow do you find the lcm and gcd 3fgcd using euclid 27s algorithmgcd 28a 2cb 29gcd in data structureeuclidean theorem for gcdwhat is gcd calculating algorithmeuclid 27s algorithm using random integershow to find gcd and lcmgcd 28a 2cb 29 3d gcd 28b 2ca 29gcd program explainbasic and euclidean algorithmlcm to gcdc program for lcm and gcdhow to prove euclid 27s algorithmgcd clcm without gcdalgorithm for gcdgcd algorithmgcd 2836 2c0 29gcd and lcm cgcd problem examplewrite a program to find out gcd 28greatest common divisor 29 using the following three algorithms a 29 euclid e2 80 99s algorithmalgorithm gcdgcd 28a 2c b 29 3c ause gcd and lcm in real lifegcd 280 2c 5 29euclidean algorithm for finding the gcd of two numbersgcd using euclidean algorithmgcd algorithm arraygcd algorithme ceuclid 27s algorithm gcdeuler 27s algorithm for gcduse euclid 27s 2 algorithm eudiam algorithm gcdlcm in terms of gcdgcd 28a 2c b 29 3a while b 21 3d 0 3a a 2c b 3d b 2c a 25 b return awhy we need gcd and lcmgcd and lcm program in javaif gcd 28a 2cb 29 3ca 2c then lcm 28a 2cb 29 3ca euclid algorithm for gcdexplanation 3a solving quadratic equations is not an application of euclid e2 80 99s algorithm whereas the rest of the options are mathematical applications of euclid e2 80 99s algorithm gcd and lcm of a numberformula to find gcd and lcmfind lcm from gcdgcd lcm stands forthe gcd 28m 2cn 29 gcd algorithmcalculate lcm from gcdgcd function javagcd lcm referencegcd equation with lcmeuklidean algorithm for determining the greatest common divisorgcd 28a 2c a 2bb 29find gcd algorithmeuclidean algorithm for gcd of two numberseuclidean algo to find gcdgcd lcm sample problems in cgcd 28a b 29 3dgcd 28a a 2bb 29best gcd algorithmgcd vs lcmeuclidean algorithm cryptographygcd algorithm step by stepbasic and euclidean algorithm for cryptographygcd and lcm of two numberseuclids gcd algorithmeuclid algorithmlcm and gcdimplement euclid 27s algorithm to compute the gcdlcm gcd in c programmingeuclid 27s algorithmeucid formula seeuclidean algorithm for gcd examplegcd and lcm of three numbersgcd 28a 2cb 29 3d agcd built in functionhow to get lcm from gcdgcd 26 lcm full formlcm from gcdgcd 28a 2cb 29 3d 1algorithm of gcd in ceuclidean algorithm gcdhow to find gcd and lcm of two numbersgcd greedy algorithmgcd lcm formula for programmingwhat is the algorithm for gcdgcd and lcm