ARITHMETIC WORKSHEETS

Checking GCD inputs that include zero or a negative sign

The GCD tool works with absolute values. This guide shows what it returns when one input is zero or negative, and why those results follow from the definition of a divisor.

Zero as an input to a divisor problem

A number d divides n if n ÷ d is a whole number with no remainder. Zero divided by any nonzero d is 0, which is a whole number, so every nonzero integer divides 0. For the pair 0 and 18, the common divisors are therefore exactly the divisors of 18: 1, 2, 3, 6, 9 and 18. The greatest of them is 18, so gcd(0, 18) = 18. The Euclidean rule agrees. With gcd(a, b) = gcd(b, a mod b), the pair (0, 18) becomes (18, 0 mod 18), which is (18, 0), and the process stops with 18 once the second value reaches zero. The GCD tool returns 18 for this input.

Why a negative sign does not change the GCD

Divisibility depends on the size of a number, not its sign. Since -18 = 18 × (-1), any whole number that divides 18 also divides -18. For -18 and 12, the common positive divisors are 1, 2, 3 and 6, and the greatest is 6. The tool applies absolute values first, so gcd(-18, 12) = gcd(18, 12) = 6. Swapping the order gives the same answer: gcd(12, -18) = 6. This matches the common convention that a GCD is reported as a nonnegative number. Some textbooks leave the sign open for negative inputs, so a worksheet that compares tools should state which convention it uses before treating two answers as different.

Reading the three worked cases

The cases below the article give the pair (0, 18) with result 18, the pair (-18, 12) with result 6, and the reversed pair (12, -18) with result 6. They test three different properties in order. The first confirms that a zero input leaves the other magnitude unchanged. The second confirms that a negative sign is ignored. The third confirms symmetry, because the greatest common divisor of a and b is the same as that of b and a. If a tool returned -6 for the second case or 12 for the third, it would be using a different sign or ordering convention, and that is the thing the cases are designed to reveal.

The pair zero and zero

The case gcd(0, 0) has no greatest common divisor in the strict sense, because every integer divides 0 and there is no largest integer. The tool returns 0 for this input as a computational convention, which keeps the Euclidean loop from failing and makes gcd(a, 0) = |a| hold for every a. That result should be read as a boundary behavior, not as a divisor. In particular, it cannot be used to reduce a fraction or to size a group, since dividing by 0 is undefined. The worked examples here always pair zero with a nonzero value so that the GCD is a real greatest positive common divisor.

More signed pairs to try

Try -18 and -12. Both signs drop out and the GCD is 6. Try 0 and -7, where the result is 7 because the divisors of 7 are the only common divisors. Try 0 and 1, where the result is 1. A pair like -35 and 14 gives 7, since 35 = 5 × 7 and 14 = 2 × 7 and the cofactors 5 and 2 share nothing. In each case, remove the signs first, check whether either number is zero, and then run the usual process. A quick test of a result is to divide each original magnitude by it and confirm that both quotients are whole numbers whose own GCD is 1.

Where signed and zero values appear

Signed integers come up when a worksheet uses differences, such as a - b, as inputs. A difference of two measurements may be negative or zero, and a tool that rejects them forces extra steps. Zero appears when one quantity is absent, for example a recipe component with 0 units in one batch. Reducing the ratio 0 : 18 gives 0 : 1, because the GCD 18 divides both terms. Fractions with a zero numerator, such as 0/18, reduce to 0/1 by the same rule. Knowing the zero and sign behavior prevents surprise when a spreadsheet column mixes positive, negative and empty values.

Fraction reduction needs a nonzero partner

Reducing a fraction divides the numerator and denominator by their GCD. That works when the denominator is nonzero. A pair like (0, 0) cannot be reduced because it is not a valid fraction, and a GCD of 0 would cause a division by zero. For a fraction such as -18/12, the GCD is 6 and the reduced fraction is -3/2, with the sign kept on the numerator by the usual convention. Checking the GCD of the magnitudes first, then restoring the sign afterward, is a clean way to organize the work. The tool output for the magnitudes is always positive, which makes it easy to divide by.

A divisibility test for a returned GCD

Whatever tool produces a GCD, you can test the answer in two quick steps. First, confirm that it divides both original magnitudes. For the pair 18 and 12 and a result of 6, the quotients are 3 and 2, both whole numbers. Second, confirm that the quotients themselves share no factor greater than 1. The numbers 3 and 2 are coprime, so no larger common divisor was missed. If a tool had returned 3 instead, the quotients 6 and 4 would still share the factor 2, which shows 3 was too small. For a zero input, the first step reads differently: 0 ÷ 18 = 0 is a whole number, so 18 passes, and the second step compares the quotients 0 and 1, where 1 divides both and nothing larger does.

What the check does not cover

These examples describe how a single tool treats zero and negative integers. They do not set a rule for every programming language, library or textbook. Some libraries return a negative GCD for negative input, and some raise an error for zero. A worksheet that exports GCD values to another system should record the convention used so that the receiving system can interpret them. The cases also use whole numbers only. A GCD of decimal values is a different problem that requires scaling the values to integers first, and the tool in these examples does not do that automatically. Very large integers are another boundary. The tool follows a short loop of remainders, so even long inputs finish quickly, but you should still keep the source digits in a record so a later reader can repeat the run. Finally, note that the sign convention only matters for display. Every divisibility statement in this guide is the same for 18 and -18, so a pair of worksheets that disagree on sign can still agree on every fact that matters.

Reproduce the checks

Zero with a nonzero value

Open the GCD calculator and enter:

First integer
0
Second integer
18

Expected output:

Greatest common divisor

18

Every positive divisor of eighteen also divides zero.

Signed input

Open the GCD calculator and enter:

First integer
-18
Second integer
12

Expected output:

Greatest common divisor

6

The sign does not change the positive divisibility set.

Reversed signed inputs

Open the GCD calculator and enter:

First integer
12
Second integer
-18

Expected output:

Greatest common divisor

6

Input order does not change the GCD.

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