Library · Between the Challenge and the Olympiad · Chapter 9
Counting One Thing by Counting Another
On this page
- Problems
- Solutions
- Solution: PRMO 2015 Part A, Q14
- Solution: IOQM 2023, Q8
- Solution: IOQM 2025 Part SEP, Q28
- Solution: PRMO 2014, Q20
- Solution: PRMO 2019, Q24
- Solution: IOQM 2022, Q10
- Solution: IOQM 2022, Q21
- Solution: IOQM 2023, Q7
- Solution: IOQM 2026, Q7
- Solution: IOQM 2020, Q26
- Solution: IOQM 2022, Q22
- Solution: IOQM 2025 Part SEP, Q7
- Solution: IOQM 2026, Q18
- Solution: IOQM 2021 Part B, Q3
- Solution: IOQM 2022, Q20
- Solution: IOQM 2024, Q24
Problems
Problem 1
At a party, each man danced with exactly four women and each woman danced with exactly three men. Nine men attended the party. How many women attended the party?
Problem 2
Given a tile and seven dominoes ( tile), find the number of ways of tiling (that is, cover without leaving gaps and without overlapping of any two tiles) a rectangle using some of these tiles.
Problem 3
The six faces of a cubical die are numbered with , , , , , in such a way that the product of the numbers on any pair of opposite faces is . Two such dice are stacked one on top of another. If is the greatest possible sum of the 9 visible numbers (for all such arrangements of dice), find the sum of the squares of the digits of .
Problem 4
What is the number of ordered pairs where and are subsets of such that neither nor ?
Problem 5
A rectangle () is divided into unit () squares. Each square of this rectangle is coloured red, blue or green. Let be the number of colourings of the rectangle in which there are an even number of red squares. What is the largest prime factor of ? (The number of red squares can be zero.)
Problem 6
Consider the 10-digit number . We obtain a new 10-digit number from according to the following rule: we can choose one or more disjoint pairs of adjacent digits in and interchange the digits in these chosen pairs, keeping the remaining digits in their own places. For example, from , by interchanging the 2 underlined pairs, and keeping the others in their places, we get . Note that any number of (disjoint) pairs can be interchanged. Find the number of new numbers that can be so obtained from .
Problem 7
An ant is at a vertex of a cube. Every 10 minutes it moves to an adjacent vertex along an edge. If is the number of one hour journeys that end at the starting vertex, find the sum of the squares of the digits of .
Problem 8
Unconventional dice are to be designed such that the six faces are marked with numbers from 1 to 6 with 1 and 2 appearing on opposite faces. Further, each face is coloured either red or yellow with opposite faces always of the same colour. Two dice are considered to have the same design if one of them can be rotated to obtain a dice that has the same numbers and colours on the corresponding faces as the other one. Find the number of distinct dice that can be designed.
Problem 9
Find the number of positive integers satisfying all the following conditions:
(a) The digits of lie in the set . (Digits may be repeated.)
(b) The sum of the digits is .
(c) If occurs as a digit, then it can occur only immediately to the right of .
Problem 10
In the figure below, of the discs are to be coloured black and are to be coloured white. Two colourings that can be obtained from one another by a rotation or a reflection of the entire figure are considered the same. There are only four such colourings for the given two colours, as shown in Figure 1. In how many ways can we colour the 6 discs such that 2 are coloured black, 2 are coloured white, 2 are coloured blue with the given identification condition?
Problem 11
A binary sequence is a sequence in which each term is equal to 0 or 1. A binary sequence is called friendly if each term is adjacent to at least one term that is equal to 1. For example, the sequence is friendly. Let denote the number of friendly binary sequences with terms. Find the smallest positive integer such that .
Problem 12
Let be the number of nine-digit integers that can be obtained by permuting the digits of and which have at least one to the right of the right-most occurrence of . What is the remainder when is divided by ?
Problem 13
In the plane let the positive end of the -axis be directed towards East and the positive end of the -axis be directed towards North. Suppose you are at and you want to go to . At every move you are allowed to move unit length towards East or unit length towards North from your current position but you are not allowed to visit any point where both are odd. Find the number of such paths .
Problem 14
Let be a regular polygon with vertices. By a labelling of we mean an assignment of integers to the vertices in some order. A labelling is considered good if the path consisting of line segments to , to , … and to does not self-intersect. If is the number of good labellings, what is the remainder when is divided by ?
Problem 15
For a positive integer , let denote the number of arrangements of the integers into a sequence such that for all , and , for all , . For example, is , since the possible arrangements are and .
Find .
If is the largest non-negative integer so that divides , show that .
Find the largest non-negative integer so that divides .
Problem 16
For an integer and a permutation of , we say is a landmark point if and . For example, for , the permutation has four landmark points: , , and . For a given , let denote the number of permutations of with exactly one landmark point. Find the maximum for which is a perfect square.
Problem 17
Consider the set of all polynomials whose coefficients are in the set of . Let . The number of polynomials in of degree such that the product is also in is:
Problem 18
Consider a sequence of real numbers of finite length. Consecutive four term averages of this sequence are strictly increasing, but consecutive seven term averages are strictly decreasing. What is the maximum possible length of such a sequence?
Solutions
Solution: PRMO 2015 Part A, Q14
Count the dancing pairs twice, once from the men’s side and once from the women’s, and the two counts must agree.
Call a pair consisting of a man and a woman who danced together a dancing pair, and let be the number of women. Counting these pairs from the men’s side, each of the men appears in exactly of them, so there are pairs. Counting from the women’s side, each woman appears in exactly , so there are pairs.
The same collection has been counted both times, so
This is double counting in its purest form, and the shape recurs constantly: whenever a problem gives you a fixed number of connections at each end of a two-sided relationship, count the connections themselves and set the two totals equal.
Answer 12
Solution: IOQM 2023, Q8
Split the count by whether the square tile is used; without it the tilings are counted by the Fibonacci numbers, and with it the square’s position cuts the strip into two shorter strips tiled by dominoes alone.
Let be the number of ways to tile a rectangle with dominoes only. Looking at the leftmost column, either one vertical domino fills it, leaving , or two horizontal dominoes fill the first two columns, leaving . So giving for through . In particular there are tilings that use dominoes alone, and they use exactly seven dominoes, which is what we have.
Now suppose the tile is used. Only one such tile is available, so it is used at most once. It covers two adjacent columns, say columns and with , and it splits the strip into a piece on the left and a piece on the right, each tiled by dominoes alone. The number of tilings using the square is therefore Each of these uses five dominoes, comfortably within the seven available.
The two cases are disjoint and cover everything, so the answer is .
Answer 59
Solution: IOQM 2025 Part SEP, Q28
Only three faces are hidden, and two of them are opposite faces of the lower die, so their sum is at least ; the third hidden face should be the smallest number, .
The exponents on opposite faces add to , so opposite faces carry , or . Each die carries all six numbers, with total so the two dice together carry .
Stacking hides exactly three faces: the bottom face of the lower die, the top face of the lower die and the bottom face of the upper die. The first two are opposite faces of the same die, so their sum is one of and the smallest is . The third hidden face is any face of the upper die and can be as small as .
So the least possible hidden total is and The sum of the squares of the digits is .
Answer 11
Solution: PRMO 2014, Q20
Count each element’s four possible states independently, then subtract the pairs with or by inclusion-exclusion.
Build a pair element by element. Each of the five elements is in only, in only, in both, or in neither, four independent choices, so there are ordered pairs altogether.
Now count the bad ones. For , each element must avoid the state “in only”, leaving three choices, so there are such pairs, and likewise with . Pairs counted twice are those with both inclusions, that is , of which there are . By inclusion-exclusion the bad pairs number
Hence the answer is
Answer 570
Solution: PRMO 2019, Q24
Count the colourings once with every colouring positive, and once with an odd number of reds carrying a minus sign. Adding the two totals isolates the even-red count.
For one square, blue and green contribute each and red contributes , so the signed total is , while the ordinary total is . Adding gives , twice the number of choices with an even number of reds. The same separation can work with any number of squares. The ordinary total number of colourings is . Now attach to each colouring the sign and add: because each square independently contributes for either of the two non-red colours and for red. The left-hand side is (even-red count) minus (odd-red count), while the total is their sum, so
Therefore using with , which spares the division of by . Finally , so the largest prime factor is .
Answer 37
Solution: IOQM 2022, Q10
A choice of disjoint adjacent pairs is a matching on a path of ten vertices, and those are counted by the Fibonacci numbers.
The ten digits of are all different, so two different choices of swaps always produce two different numbers, and we may count the choices directly.
For three positions, there are just three disjoint-swap choices: no swap, swap positions , or swap positions . Both swaps together are forbidden because they share position . Think of the ten digit positions as vertices of a path, with an edge joining each adjacent pair. Choosing disjoint adjacent pairs to swap is exactly choosing a set of edges no two of which share a vertex, that is a matching. Let be the number of matchings on a path of vertices. Looking at the last vertex, either it is unmatched, leaving , or it is matched to its neighbour, leaving . So which is the Fibonacci sequence shifted along. Running it out, , , and onwards to .
One of those choices is the empty one, which leaves unchanged and so produces no new number. The count of new numbers is .
Answer 88
Solution: IOQM 2022, Q21
Track how many ways the ant can be at the start, at a neighbour, at a face-diagonal vertex, or at the opposite corner. Four numbers suffice, because the cube looks the same from every vertex.
each arrow counts neighbours
An hour is six moves of ten minutes each, so we want the number of closed walks of length six from a fixed vertex of a cube.
Classify each vertex by its distance from the start: there is vertex at distance , three at distance , three at distance , and one at distance . Because every vertex of the cube looks the same as every other, with three neighbours apiece, the count of walks depends only on this class, so let record how many length- walks end in each class. From the adjacency, a vertex at distance has all three neighbours at distance , a vertex at distance has one neighbour at distance and two at distance , a vertex at distance has two neighbours at distance and one at distance , and the vertex at distance has all three neighbours at distance . A walk arriving in a class came from a neighbouring class, so
Starting from and stepping six times: Half the entries are zero because every move changes the distance by one, so after an even number of moves the ant is at distance or . The number of walks that finish where they started is .
The question asks for the sum of the squares of the digits of , which is .
Answer 74
Solution: IOQM 2023, Q7
Because all six numbers are different, no rotation other than the identity can fix a design, so the rotations cut the count of labelled coloured dice by exactly .
First count dice with the faces labelled and coloured in space, ignoring the identification by rotation. The face carrying can be any of the , its opposite face must carry , and the remaining four numbers can be placed on the remaining four faces in ways. That gives numberings. Colouring is independent: the three pairs of opposite faces each take one of two colours, so colourings. In total there are labelled coloured dice sitting in space.
Now bring in the rotations. A rotation of the cube is fixed by saying where one chosen face goes, which is any of the faces, and then how that face is turned, which is any of quarter turns; so there are of them. Two of our dice have the same design exactly when a rotation carries one to the other. The count of designs would be provided no rotation other than the identity leaves a die unchanged, and that is where the distinct numbers help: a non-identity rotation moves some face to a different face, and those two faces carry different numbers, so the die is changed. Every family of dice that count as the same therefore has exactly members and
If it helps to see the same answer built up rather than divided down, fix on top and below, which uses up the freedom to rotate the die as a whole except for the four turns about the vertical axis. The four side faces can be filled with in ways, and those four turns identify them in groups of four, leaving numberings. Multiply by the colourings to get .
Answer 48
Solution: IOQM 2026, Q7
A always travels with the in front of it, and the pair adds , an odd amount among even digits. With an even total of no can appear, and what is left is counting the ordered ways to add s, s and s to .
Condition (c) says every sits immediately after an . Glue each such to its , and the number becomes a row of blocks , , and , whose digit sums are , , and . All but the last are even, and the total is the even number , so the number of blocks is even. Two of them already add up to , which is too much, so there are none, and uses only the digits , and .
Halve everything: we want the number of ordered ways to write as a sum of s, s and s. Write for the number of ways to make a total of . The first part is , or , and what follows is any arrangement of the remainder, so where (the empty sum) and of a negative number is . Each entry of the table after the first is the sum of the entries one, two and four places to its left: and in particular .
Each way of making , read left to right and doubled, is the list of digits of exactly one , so there are numbers.
Answer 31
Solution: IOQM 2020, Q26
Count colourings by averaging over the six symmetries. The two rotations fix nothing at all, because a rotation would force three discs to share a colour and no colour has three discs.
The six discs sit in a triangular array, three at the corners and three at the midpoints of the sides, and the symmetries of that array are the six symmetries of an equilateral triangle: the identity, two rotations, and three reflections. Two colourings count as the same exactly when one symmetry carries one to the other, so what we are counting is families of colourings, each family holding the ones the symmetries carry into each other.
The obvious move is to count the labelled colourings and divide by , and it fails, because is not the answer. It fails because the six symmetries do not always give six different labelled colourings: a colouring that a reflection leaves alone is reached in fewer than six ways, so dividing by six undercounts it. What is needed is a division that adjusts for exactly that.
The tool is to average, over the six symmetries, the number of colourings each one leaves unchanged, and since that is not a school result, here is why it works. Count the pairs in which the symmetry leaves the colouring unchanged, in two ways. Summing over gives the total of the fixed-colouring counts. Summing instead over : fix a colouring and let be the set of symmetries leaving it unchanged. Two symmetries and send to the same colouring exactly when applying and then undoing leaves unchanged, so the six symmetries fall into groups of size , one group for each colouring in the family of . The order matters: doing it the other way round tests a different symmetry, and for the reflections that test gives the wrong answer. Hence times the size of that family is , so each colouring in a family contributes , and the whole family contributes . Adding over families, the two counts give which is the averaging rule.
Take the symmetries in turn. The identity leaves every colouring unchanged, and the number of ways to give two discs each of three colours to six labelled positions is .
The two rotations fix nothing. A rotation through permutes the three corners in a single cycle and the three midpoints in another, so any colouring it leaves unchanged must give all three corners one colour and all three midpoints another. That would need three discs of some colour, and we have only two of each, so the count is for each rotation.
Each reflection fixes one corner and the midpoint of the opposite side, while swapping the other two corners with each other and the other two midpoints with each other. A colouring unchanged by it must give the swapped corner pair a single colour and the swapped midpoint pair a single colour, and those two colours must differ, since otherwise that colour would appear four times. The remaining colour then goes to the two fixed discs, which is exactly the two we have left. So there are such colourings for each of the three reflections.
Averaging over the six symmetries,
Answer 18
Solution: IOQM 2022, Q22
The two neighbours of an interior term lie in the same parity class of positions. Split the sequence into its odd and even positions: each must avoid two consecutive zeros, with the end conditions fixing a few ones.
Read the condition position by position. The first term needs and the last needs , those being their only neighbours. For an interior position , the requirement is that and are not both .
That last condition is the useful one, because and have the same parity and are consecutive within their parity. As runs over , the pairs run over every consecutive pair of the odd-indexed terms and every consecutive pair of the even-indexed terms. So a sequence is friendly exactly when and neither the odd-indexed subsequence nor the even-indexed subsequence contains two consecutive zeros. The two subsequences are otherwise independent, so the count is a product.
It is worth splitting one sequence by hand before going on. For take The odd positions carry and the even positions carry . Neither has two zeros in a row, the required and are both , and one may check position by position that the sequence really is friendly. Notice that the two rows never look at each other.
The building block is the number of binary strings of length with no two consecutive zeros, which is with : the first term is or , and the two cases leave strings of length and with the same property. Fixing one end to be a costs one step of the recursion, giving ; fixing both ends gives .
The odd positions are and the even ones , both of length . The condition fixes the last odd term and fixes the first even term, so each subsequence contributes and
Now the odd positions number and carry no fixed term, contributing ; the even positions number and have both ends fixed, since is the first and the last, contributing . So
Now evaluate. With the even case gives , still below , and the odd case gives Both formulas increase with , so the smallest such is .
Answer 11
Solution: IOQM 2025 Part SEP, Q7
Count the opposite: the arrangements with no after the last are exactly those ending in a followed only by twos, and there are just three shapes to count.
The digits are two s, three s and four s, so the total number of arrangements is
Now count the arrangements in which no lies to the right of the last . Everything after the last is then a , say of them with . Such an arrangement is completely described by choosing , placing a in position , filling the last places with twos, and arranging the remaining digits, which are three s, three s and twos, in the first places. So the count is which is .
Hence , and the remainder on division by is .
Answer 40
Solution: IOQM 2025 Part SEP, Q28
From a point with one odd coordinate the next step is forced, so the whole path is decided at the points with both coordinates even, and it moves in double steps.
so the walk hops between the filled dots
The forbidden points are those with both coordinates odd. Look at where you can be.
At either step is legal.
At a step North would land on two odd coordinates, so you must go East, arriving at .
At you must likewise go North.
So from an even-even point every choice commits you to two steps, taking you either two East or two North, and back to an even-even point.
The journey therefore consists of double steps from to the last even-even point, and since the destination is , with odd and even, that last point is and the journey finishes with a single step East. The double steps take you from to , which needs double steps East and double steps North in some order:
Answer 84
Solution: IOQM 2026, Q18
Build the path one vertex at a time. The vertices already used always form an unbroken run around the octagon with the current vertex at one end, so every step has just two choices, one at each end of the gap.
A labelling is a path through all eight vertices, visited in the order . The claim is that in a good labelling, at every stage, the vertices visited so far are consecutive around the octagon and the current vertex is at one end of that run.
At the start the run is one vertex. Suppose the claim holds, the current vertex is , and the unvisited vertices form the complementary run . Suppose the path next goes to a vertex of that is not one of its two ends. The segment is a chord with unvisited vertices on both sides of it: those of between and , and those beyond . The rest of the path starts at and has to visit both sides, so at some moment it steps along a segment whose ends lie strictly on opposite sides of the chord . In a convex polygon such a segment crosses , and the labelling is not good. So the path moves to an end of , and the claim holds one step later.
Conversely, a step to an end of crosses nothing already drawn. If the end is next to the step is a side of the octagon. If it is the other end, every visited vertex other than lies on one side of the new chord, so every earlier segment does too, and none can cross it.
So the good labellings are counted by their choices. There are places for vertex . Each of vertices to has two choices, the two ends of , which are different while has at least two vertices. Vertex is forced. Hence and the remainder on division by is .
Answer 12
Solution: IOQM 2021 Part B, Q3
Hang the numbers on a binary tree, above and . The condition says every number beats the two below it, so the largest sits at the top and the two branches are independent copies of the same problem; that gives a product recurrence, and one short lemma counts the twos in a factorial.
What the condition means
Place at the nodes of a binary tree, with the parent of and . The two conditions say precisely that every number is larger than the two hanging beneath it. So , at the top, is the largest of all, and once it is placed the two branches have nothing to do with each other: each is the same problem on fewer nodes.
That picture is the whole method. Choosing which numbers go left and which go right is free, and then each branch is counted the same way, so every count below will be a binomial coefficient times two smaller counts. An arrangement of this kind is called a heap, and the name will not be asked to do any work beyond that.
(a)
For the tree is the full tree of three levels: a root with two subtrees of three nodes each. The root must hold . Of the remaining six numbers, choose three for the left subtree in ways, and arrange each subtree in ways. Hence
A lemma on powers of two
For example, contains four factors of . The number is in binary, so it has two ones, and . This is the pattern we will prove. Write for the exponent of in , and for the number of ones when is written in binary. The claim is
The proof is an induction that splits on whether is even or odd, and it needs only two observations of each kind. Among the odd numbers carry no factor of at all, while the even ones are , whose product is . So the second because the extra factor is odd. On the other side, doubling a number in binary just appends a zero and adding one after that turns it into a one, so
Now induct. The claim holds at , where both sides are . Suppose it holds below . If then and if then That is the lemma, and nothing outside it is used below.
One consequence is worth recording now, for . Since and ,
(b) Full trees
For the tree is full, and the same argument as in part (a) gives The exponent of in that binomial coefficient is : by the lemma it is , and , so the whole thing is .
Writing for the exponent of in , the recurrence reads And satisfies it, since with correct. So , as required.
(c) One node more than a power of two
For and , the tree has its root, a left subtree of nodes and a right subtree of nodes. The same splitting gives which one may check at : .
Let be the exponent of in . Using the consequence of the lemma recorded above and part (b), Since gives , summing the geometric series leaves
So the largest with dividing is .
Answer proof
Solution: IOQM 2022, Q20
Counting gives , and the finish is a congruence: is modulo once , while every square is , or .
First identify what a landmark is. The condition says the two neighbours lie on the same side of , so is either larger than both, a peak, or smaller than both, a valley. Exactly one landmark therefore means the permutation rises to a single peak and then falls, or falls to a single valley and then rises.
A small peak example is : after choosing to lie left of the maximum , the increasing left part and decreasing right part are forced. A valley example is . The shared peak or valley is repeated in the display only to mark the two runs. Count the peak case. The peak is larger than everything around it and the sequence is increasing up to it and decreasing after, so the peak is the largest value, . The elements to its left are then determined as a set, since they must appear in increasing order, and likewise those to its right. So a permutation of this kind is exactly a choice of which elements of go to the left. That choice may not be empty, which would put first and leave no interior landmark, nor everything, which would put last. Hence permutations with one peak, and by the same argument with the smallest value, with one valley. The two families do not overlap, so
Now ask when is a perfect square. Since is already a square, the question is exactly whether is one. For it equals , so and works. For it equals , which is not a square.
For , so that , look modulo . Since , But the squares modulo are only , and , since an even number squares to or and an odd number squares to . So is never a square once , and no can work.
The largest, and in fact the only, value is .
Answer 3
Solution: IOQM 2024, Q24
The coefficient of in is , so keeping every coefficient at most means no two of the chosen exponents may differ by , or .
Write with each and , since the degree is exactly . Because , with the convention that outside the range. There is no carrying anywhere: these are integer coefficients, not binary digits. So the requirement is that for every ,
Read off what that forbids. Taking and together says no two chosen exponents differ by ; taking and says none differ by ; and taking and , which appear in the same sum, says none differ by . Conversely, if no two chosen exponents differ by , or , then in each sum at most one term is . So the condition is exactly
Now count. The set of exponents is a subset containing , with all gaps at least . Removing leaves a subset of with gaps at least , of some size . For example, three of the remaining exponents might be . Compressing the compulsory gaps moves them to : The compressed entries are still distinct, and adding back recovers the original choice. In general such subsets are counted by subtracting from the second element, from the third and so on, which turns them into arbitrary -element subsets of a set of numbers. So there are of them, and
Answer 50
Solution: IOQM 2025 Part SEP, Q7
Comparing two neighbouring four-term averages says only , and comparing seven-term averages says only ; a contradiction appears exactly when steps of and can be arranged into a loop that fits inside the sequence.
Let the sequence be . Two consecutive four-term averages differ by and all but the end terms cancel, so the condition is The same cancellation on the seven-term averages, now decreasing, gives
Draw the indices as dots and put an arrow from to whenever one of those requirements says . There are two kinds of arrow: from to , and from to , the second because reads as an arrow pointing backwards from to . Every arrow means the same thing, that the value at its head is the larger.
Now the question is whether such a picture can be filled in with real numbers, and the answer is that it can exactly when the arrows cannot be followed round into a loop. One direction is clear: following a loop all the way round would give .
For the other, suppose there is no loop. Repeatedly pick a dot that no remaining arrow points to, which is always possible when there is no loop, since otherwise one could keep walking backwards along arrows for ever and would have to revisit a dot. Rub it out and carry on, listing the dots in the order chosen, then hand out the values along that list. Every arrow then runs from a smaller value to a larger one: if an arrow goes from to and were still on the board when was chosen, that arrow would be pointing at and could not have been chosen. So is always rubbed out first and always gets the smaller value. Hence the sequence exists.
The direction of that sweep matters. Picking a dot with no arrow leaving it and then counting upwards would put the large values at the wrong end and reverse every inequality.
Here is the observation that settles both directions at once: modulo the two moves are the same, since . So every move advances the index by modulo , and a loop of moves needs , hence . Moreover the positions along consecutive moves occupy eleven different remainders modulo , because is coprime to , so they are eleven different indices.
Therefore no loop can fit inside , and for the inequalities are consistent: list the indices in an order compatible with every required comparison, which is possible precisely because there is no loop, and assign increasing values along that list.
For a loop does fit, and here it is: seven steps of and four of , every index between and . Going once round would give . Any longer sequence contains this loop as well.
Hence the greatest possible length is .
Answer 10