English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I would like to implement a function that would, give me the GCD of 2 number, only using Multiplication and Division (no subtraction or addition)

2007-04-14 04:54:54 · 2 answers · asked by Verident 2 in Science & Mathematics Mathematics

2 answers

Find the prime factorization fo the two numbers. Form a third factorization consisting of the lower power of each prime found in the first two numbers. This resulting factorization represents the GCD. If you take the higher power instead, you get the LCD (least common denominator).

For instance, try 12 and 90. They factor as
12 = 2^2 * 3^1
90 = 2^1 * 3^2 * 5

from this, take the lower power of each prime:
GCD = 2^1 * 3^1 = 6
Also,
LCD = 2^2 * 3^2 * 5 = 180

One neat property is that GCD*LCD = 12 * 90. Yes, this is a provable property.

2007-04-14 05:25:00 · answer #1 · answered by norcekri 7 · 1 0

Take the discomposition of each number into its prime factors
The GDC would be the product of the common prime factors chosen with its least exponent
Ex
140 and 98
140 =2^2*5*7
98= 2*7^2
GCD = 2*7=14

2007-04-14 06:52:46 · answer #2 · answered by santmann2002 7 · 0 0

fedest.com, questions and answers