ARITHMETIC WORKSHEETS

Checking a Euclidean GCD step with the remainder

Replacing a pair of integers by the smaller one and the remainder leaves their greatest common divisor unchanged. This guide checks that on 48 and 30 and explains why the Euclidean algorithm works.

The claim in one sentence

If a number a equals a multiple of b plus a remainder r, then a and b have exactly the same common divisors as b and r. Because the two pairs share the same set of common divisors, they share the same greatest one. In symbols, gcd(a, b) equals gcd(b, r), where r is a minus q times b for some whole number q. This is the engine behind the Euclidean algorithm. Each step replaces a large pair by a smaller pair with the same gcd, and the numbers shrink until the remainder is zero. The last nonzero remainder is the answer. The GCD calculator on this site reports the final value, and the guide uses it to confirm each intermediate pair. The claim also holds for the quotient 0, in which case a is smaller than b and the step simply swaps the pair, so the algorithm needs no special handling when the inputs arrive in the wrong order.

Why the common divisors are preserved

Suppose d divides both a and b. Then d divides a minus q times b, because both terms are multiples of d, so d divides r. Hence every common divisor of a and b also divides r, and so is a common divisor of b and r. Now suppose d divides both b and r. Then d divides q times b plus r, which is a, so d is a common divisor of a and b. The two sets of common divisors are the same. The argument uses nothing but the fact that sums and differences of multiples of d are multiples of d. It works for any integer q, which is why the step can remove a whole multiple and still keep the gcd.

The default chain for 48 and 30

Divide 48 by 30. The quotient is 1 and the remainder is 18, because 48 equals 1 times 30 plus 18. So gcd(48, 30) equals gcd(30, 18). Next, 30 equals 1 times 18 plus 12, giving gcd(30, 18) equals gcd(18, 12). Then 18 equals 1 times 12 plus 6, giving gcd(18, 12) equals gcd(12, 6). Finally, 12 equals 2 times 6 plus 0, and the remainder is zero, so the gcd is the last divisor, 6. The calculator confirms 6 for the pairs (48, 30), (30, 18) and (18, 12), which are the first three stages. Each stage uses smaller numbers. The pairs 48 and 30, 30 and 18, and 18 and 12 all have 6 as their greatest common divisor, and nothing larger divides both members of any pair.

What goes wrong with a wrong remainder

The preservation holds only when the remainder is correct, meaning a minus a whole multiple of b. If you subtract something that is not a multiple of b, the common divisors can change. From 48 and 30, a careless remainder of 20 gives the pair 30 and 20, whose gcd is 10. That is not 6, so the shortcut broke the answer. Another typical slip is subtracting twice when the quotient was one, which can leave a negative or too-small value. The check is simple: after finding r, confirm that a equals q times b plus r with r between 0 and b minus 1. If the equation fails, or r is as large as b, recompute. The calculator provides an independent check, because it works with the original integers and not with your intermediate steps.

A longer classic example: 1071 and 462

A frequently used example is the pair 1071 and 462. Divide: 1071 equals 2 times 462 plus 147. Then 462 equals 3 times 147 plus 21. Then 147 equals 7 times 21 plus 0. The last nonzero remainder is 21, so gcd(1071, 462) is 21. Every pair along the chain has the same gcd: (1071, 462), (462, 147) and (147, 21) all give 21. You can verify by factoring. 1071 is 21 times 51, and 462 is 21 times 22, and 51 and 22 share no common factor. The example shows how fast the numbers fall. Three divisions replaced a four-digit pair with a two-digit pair. A direct search for the largest shared divisor would have taken far more steps.

Using the gcd to reduce fractions

A major use of the gcd is reducing fractions. The fraction 48 over 30 has gcd 6 in numerator and denominator, so dividing both by 6 gives 8 over 5. The reduced form is in lowest terms because the new numerator and denominator have no common divisor above 1. The gcd also gives the least common multiple, using lcm(a, b) equal to a times b divided by gcd(a, b). For 48 and 30 that is 48 times 30 divided by 6, which is 240. Adding fractions with denominators 48 and 30 would use 240 as the common denominator. Because the Euclidean step preserves the gcd, any intermediate pair in the chain gives the same reduction factor, which makes it easy to cross-check.

How many steps are needed

The number of division steps stays small even for large inputs. The worst case occurs for consecutive Fibonacci numbers, as the mathematician Gabriel Lame showed in 1844. For 89 and 55 the chain is 89 equals 1 times 55 plus 34, then 55 equals 1 times 34 plus 21, then 34 equals 1 times 21 plus 13, and so on through 21, 13, 8, 5, 3, 2 and 1, finishing at a gcd of 1. That takes 9 divisions for a pair of two-digit numbers. For most pairs the algorithm finishes much faster. In general the number of steps grows in proportion to the number of digits, not to the size of the numbers, and this makes the method practical for integers with hundreds of digits.

Coprime numbers and a gcd of 1

Two integers are coprime when their gcd is 1. The Euclidean chain ends with a remainder of 1 and then 0 in that case. Coprimality matters in fractions, in modular arithmetic and in cryptography, where an inverse modulo a number exists only when the number and the modulus are coprime. In the example of 89 and 55, the answer 1 tells you that 55 over 89 is already in lowest terms. If the gcd is larger than 1, the shared factor can be cancelled. The calculator reports the gcd directly, and you can read coprimality from it. A gcd of 1 does not mean that either number is prime, only that they share no factor. For instance, 8 and 15 are coprime, although neither is prime. Calculator results of 1 are worth a second look when you expected a larger shared factor, since a single transposed digit in an input will usually turn a shared factor into none at all.

Negative numbers, zero and the exact-integer note

The gcd is normally defined for integers other than the pair 0 and 0, and it ignores signs, so gcd(minus 48, 30) is 6 on the calculator. For the pair 0 and 0 the calculator returns 0 by convention. The gcd of any number and 0 is the absolute value of that number, which is why the chain stops when the remainder reaches 0. The calculator works with exact integers, so no floating-point rounding can affect the result, even for large inputs. That matters because a gcd computed from floating-point approximations of large integers can be wrong. Division with remainder, as used here, is an integer operation. Dividing 48 by 30 as a decimal gives 1.6, which does not reveal the remainder 18. Work with whole-number quotients and remainders in the chain, and use the calculator to verify the final result.

Writing the gcd as a combination

The chain can be run backward to express the gcd as a combination of the original numbers, a result known as the Bezout identity. From the steps for 48 and 30, 18 equals 48 minus 30, 12 equals 30 minus 18, and 6 equals 18 minus 12. Substituting the middle line into the last gives 6 equals 18 minus (30 minus 18), which is 2 times 18 minus 30. Replacing 18 by 48 minus 30 gives 6 equals 2 times 48 minus 3 times 30, which is 96 minus 90. The coefficients 2 and minus 3 are not unique, but they exist for any pair. This is the tool used to find modular inverses, because when the gcd is 1 the combination gives an integer that multiplies one number to leave remainder 1 modulo the other. The extended algorithm records the quotients so the combination can be built without searching.

A tiling interpretation

The gcd has a geometric reading. A rectangle that is 48 units by 30 units can be covered exactly by identical squares only if the side of the square divides both lengths. The largest such square has side gcd(48, 30), which is 6, and it takes 8 squares along the long side and 5 along the short side, for 40 in all. Euclid presented the algorithm in this spirit in Book VII of the Elements, around 300 BC, as repeated removal of the smaller length from the larger. Each remainder step corresponds to cutting away the largest possible squares and continuing with the leftover strip. The picture explains why the remainder is the right thing to keep: it is what is left of the rectangle after the biggest squares have been removed, and the surviving strip tiles with the same square as the original.

Comparing with the prime-factor method

A second way to find the gcd is to factor both numbers and take the smaller exponent of each prime. Here 48 is 2 to the fourth times 3, and 30 is 2 times 3 times 5. The prime 2 appears with exponents 4 and 1, so the gcd takes 1. The prime 3 appears with exponents 1 and 1, so the gcd takes 1. The prime 5 appears only in 30, so it contributes nothing. The gcd is 2 times 3, which is 6, the same as the Euclidean result. The factor method is clear for small numbers, but it requires factoring, which becomes hard for large inputs. The Euclidean method needs only division with remainder, so it remains fast when factoring would be impractical.

Reproduce the checks

Original GCD

Open the GCD calculator and enter:

First integer
48
Second integer
30

Expected output:

Greatest common divisor

6

The first division leaves remainder eighteen.

First reduced pair

Open the GCD calculator and enter:

First integer
30
Second integer
18

Expected output:

Greatest common divisor

6

Removing the multiple preserves the GCD.

Second reduced pair

Open the GCD calculator and enter:

First integer
18
Second integer
12

Expected output:

Greatest common divisor

6

The next valid remainder step also preserves it.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Related tasks