ARITHMETIC WORKSHEETS

Checking a target that passes GCD divisibility but has no nonnegative solution

A GCD of 1 says integer solutions exist, but a count of items can never be negative, so small targets still need an explicit check.

Two questions that sound alike

Suppose you can only buy items in sizes 4 and 7 and you want a total of 5. One question asks whether integers x and y exist with 4x + 7y = 5. The other asks whether nonnegative whole numbers x and y exist, because you cannot buy minus two boxes. The greatest common divisor settles the first question only. Because gcd(4, 7) is 1, and 1 divides every integer, an integer solution exists for every target. The second question is a counting question, and the GCD cannot answer it alone. This worksheet uses the pair 4 and 7 to show where the divisibility test stops and a direct count has to take over.

Running the GCD test on 4 and 7

The GCD calculator with 4 and 7 returns 1. Neither number divides the other, and they share no prime factor, since 4 is 2 squared and 7 is prime. By Bezout's identity, every integer is then a combination 4x + 7y with integer coefficients. For target 1, one choice is 2 times 4 minus 1 times 7, which is 8 minus 7. That identity is perfectly valid, but it subtracts a size-7 item. In a purchasing, packing or scheduling problem, a negative coefficient would mean returning goods. So the GCD result tells you no divisibility obstruction exists, and it tells you nothing about whether a real collection of items works.

Testing target 5 by hand

For target 5, list the options by the number of size-7 items. One size-7 item gives 7, which already exceeds 5, so zero are allowed. With no size-7 item, the size-4 items must add to 5. Zero of them leave 5, and one leaves 5 minus 4, which is 1, a remainder that neither size can fill. Two size-4 items give 8, which overshoots. So no nonnegative combination reaches 5, even though the GCD is 1. The basic calculator confirms the leftover after one smaller item: 5 minus 4 is 1, and a leftover of 1 cannot be built from items of size 4 or 7. Small targets fail because the available steps are larger than the gap that remains.

A target that does work

Target 11 is reached by one item of each size, since 4 plus 7 equals 11. The basic calculator returns 11 for that sum. Compare that with target 8, which is two size-4 items, and target 14, which is two size-7 items. Other reachable targets include 12 (three fours), 15 (two fours and one seven), 16 (four fours) and 18 (one four and two sevens). Each of these has a concrete list of items. The method that works at any size is the same: choose a number of size-7 items that leaves a multiple of 4, and subtract. For 18, one seven leaves 11, which is not a multiple of 4, while two sevens leave 4, which is.

The list of targets that never work

For two coprime sizes a and b, the largest unreachable target is ab − a − b, a result usually credited to James Joseph Sylvester in 1884 and known as the Frobenius coin problem. With 4 and 7, that is 28 − 4 − 7, which equals 17. The unreachable targets are 1, 2, 3, 5, 6, 9, 10, 13 and 17. There are (a − 1)(b − 1)/2 of them, and (3 times 6)/2 is 9, matching the list. Every target from 18 upward can be built, so the GCD test becomes a reliable guide once the target is large enough. For small targets, list the cases directly.

What changes when the GCD is above 1

If the GCD is larger than 1, divisibility itself becomes the obstruction. With sizes 6 and 9, the GCD calculator returns 3, so only multiples of 3 can ever be reached. Target 10 fails immediately because 3 does not divide 10. Target 12 works as two sixes, and target 15 works as one six and one nine. Even a divisible target can fail when it is small: target 3 is divisible by 3, but neither size fits within it. The practical order is to test divisibility by the GCD first, which can rule out a target quickly, and then test the nonnegative counts for the targets that pass.

A procedure for larger targets with sizes 4 and 7

For any target T, try zero, one, two and so on of the size-7 items, and check whether what remains is a multiple of 4. Because 7 leaves a different remainder modulo 4 each time (7, 14, 21 and 28 leave 3, 2, 1 and 0), at most four tries are needed. Target 23 works with one seven: 23 minus 7 is 16, and 4 times 4 is 16. Target 25 fails with zero, one and two sevens, because 25, 18 and 11 are not multiples of 4, but succeeds with three: 3 times 7 is 21, and 25 minus 21 is 4, one size-4 item. The same four-try limit shows why every target above 17 can be built.

More than two sizes

The simple formula ab − a − b applies to exactly two sizes. With three or more, the largest unreachable target needs a different calculation or a search. A familiar example is a food seller offering packs of 6, 9 and 20 pieces, where the largest quantity that cannot be assembled is 43. Adding sizes shrinks the list of impossible targets, and the GCD of all sizes still has to divide the target. When you work with several sizes by hand, build a table of reachable totals from 0 upward, marking a number reachable when subtracting one size lands on an already reachable total. That table doubles as a check on the divisibility test.

State the constraints before reading the result

The GCD calculator reports a number-theory fact about integers and has no knowledge of what you are counting. Write down the item sizes, the target and the rule that counts cannot be negative before you read any output. If a collection can reuse the same size many times, the counts are nonnegative integers. If each size may be used at most once, the problem changes again, and neither the GCD nor the Frobenius result applies directly. For the 4-and-7 example, the answers are settled by the lists above: 5 fails, 11 works, and 17 is the last target that fails.

Try your own values with the Two-size whole-count combinations calculator.

Reproduce the checks

No divisibility obstruction

Open the GCD calculator and enter:

First integer
4
Second integer
7

Expected output:

Greatest common divisor

1

The GCD test alone does not settle the count constraint.

Remainder after one smaller item

Open the Basic calculator and enter:

First number
5
Operation
subtract
Second number
4

Expected output:

Result

1

The remainder cannot be built from four or seven.

Feasible larger target

Open the Basic calculator and enter:

First number
4
Operation
add
Second number
7

Expected output:

Result

11

This target has a nonnegative combination.

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