You are on page 1of 9

Combinations and Number Theory

1. Principle of Inclusion and Exclusion


Say there are 4 people in a team, A, B, C and D. They each have their own specific skills, which might be
common among some of them. We are tasked with finding the total number of unique skills the members of
our team possess.

If we add all the individual skills of A, B, C and D, we will grossly overcount because there can be common
skills between them which will be counted more than once.

Let us consider one skill at a time.

Skills common to only 1 person:


There is no overlap, so there is no correction required as such.

Skills common to 2 persons:


The skill is counted twice. We count it twice for those 2 persons, but we have to subtract 1.

Skills common to 3 persons:


The skill is counted thrice. So we subtract 1 for every possible choice of 2 people from 3. But in doing so,
we under-count. So we have to add 1 again for every possible choice of 3.
This can be represented as
3 3 3
( ) − ( ) + ( ) = 1
1 2 1

Skills common to n persons:

1. We count it once for every person. Result is n


2. We remove the overlaps for every choice of 2 persons. Result is n − ( ) n

3. We count it again for every choice of 3 persons. Result is n − ( ) + ( )


n

2
n

4. Continue this until we reach n persons. The final expression is


n n n
n
n − ( ) + ( )−. . . . −(−1) ( )
2 3 n

We know,
n n n
n 2 n n
(1 − x) = 1 − ( )x + ( )x −. . . . +(−1) ( )x
1 2 n

Putting x = 1, we get
n n n
n
0 = 1 − ( ) + ( )−. . . . +(−1) ( )
1 2 n

n n
n
⟹ n − ( )+. . . . −(−1) ( ) = 1
2 n

This proves that after the following manipulations, the skill which is common to n persons is
counted only once.

We can generalize this with set notation as follows:


∣ A ∪ B ∪ C ∣=∣ A ∣ + ∣ B ∣ + ∣ C ∣ − ∣ A ∩ B ∣ − ∣ B ∩ C ∣ − ∣ C ∩ A ∣ + ∣ A ∩ B ∩ C ∣

Which can be summed up as follows:

1. Adding the number of elements in each set.


2. Subtracting the number of elements which are common to any two pairs of sets.
3. Subtracting the number of elements which are common to any three pairs of sets.
4. And so on, for more number of sets.

An element which is common to two sets only, will only have its influence (its value counted) up to the
second step only. In general, an element which is common to n sets, will only have its influence (its value
counted) up to the nth step only. And we have proved that for such a case, it will be counted once only,
giving us the correct result.

2. Selection of identical objects


Say there are n identical objects. We can choose

• 1 of these objects in 1 way


• 2 objects in 1 way (since every possible combination of 2 objects are identical)
• n objects in n ways
• but also, 0 objects in 1 way
So there are total n + 1 ways of selecting any number of objects from n identical objects.

2.1. Selections from multiple groups of identical objects


Say there are n objects, where p objects are of one kind, q are of another kind, and r are of another kind.

Considering only the p type objects, there are (p + 1) ways of selecting any number of p type objects,
including the null case. Similarly, there is (q + 1) ways of choosing any number of the q type objects, and
(r + 1) ways of choosing any number of the r type objects.

Since we have to select p and q and r, these selections are connected by the Rule of AND. So, total number
of selections is (p + 1)(q + 1)(r + 1).

If we want to exclude the case where we don't select anything, there's only One possible case where that
happens, when we choose 0 p objects, 0 q objects, and 0 r objects. So the number of selections where we
select at least 1 object is
(p + 1)(q + 1)(r + 1) − 1

In general, if n = a + a +. . . +a where there are n objects out of which a of them are identical, a of them
1 2 k 1 2

are identical, and so on, then the number of selections of at least one object is
(a 1 + 1)(a 2 + 1). . . (a k + 1) − 1

3. Division vs Distribution
Division and Distribution are two VERY different actions.

In division, the groups into which we are dividing the objects do not have their own identity. But in
distribution, the groups have individuality and have their own identity. Think of division as just
partitioning the objects into groups, whereas if we assign or give those groups to individual people, it
becomes a distribution. Say we have 5 different balls, then (3 + 2) and (2 + 3) are different distributions, as
giving 3 balls to person A and 2 balls to person B is different from giving 2 balls to A and 3 balls to B.
However, dividing 5 balls into (3 + 2) and (2 + 3) is equivalent.

Distributions = Divisions × Arrangements

If we find the number of divisions of n objects into a certain number groups, then we do not care about the
arrangement of the groups among themselves.
3.1. Distribution vs Arrangement into groups
There is yet another term, "Arrangement into groups". In distribution, we do not care about the order of the
objects within the group itself. However, in arrangement we do consider the order of the objects within the
groups.

3.2. Example:
Consider the following letters
A, B, C, D

x Empty allowed Empty not allowed

Division

Distribution

Arrangement

3.3. Division of distinct objects into groups of given sizes


Say we have p + q + r objects and we want to divide into three groups of sizes p, q, and r. First we choose p
objects to put into one group, and then we choose q objects from the remaining ones to put into the second
group. The last one gets the remaining r objects.
So the total number of possible ways to divide the objects is

p + q + r q + r r
( ) ⋅ ( ) ⋅ ( )
p q r

Which simplifies to

(p + q + r)!

p! × q! × r!

Note that we can only use the nCr formula here because all the objects are said to be distinct.

Think of dividing a bunch of distinct marbles into a glass, a bucket, and a bathtub, and each has to be filled
up completely. There is NO way to have duplicate combinations by rearranging the groups, as the sizes of
the groups act sort of as an identity (even though groups aren't supposed to have any identity in division). So
in this case, number of divisions = number of distributions.

3.3.1. Special case when the groups are of equal sizes


In the previous case, the groups being of different sizes serves as somewhat of an identity for each group.
That is, we cannot possibly have duplicate combinations by rearranging the GROUPS among themselves.

Now say if we were dividing them among three identical buckets. Say we give A marbles to bucket 1, B
marbles to bucket 2, and C marbles to bucket 3. We could ALSO give B marbles to bucket 1, C marbles to
bucket 2, and A marbles to bucket 3. Those would be called DIFFERENT distributions, but they are the
SAME division. So using the previous formula would give the number of distributions and not divisions.

We know,
Distributions = Divisions × Arrangements of groups

So to find the number of divisions, we have to remove the duplicate cases formed by the rearrangement of
the groups AMONG themselves.
Distributions
= Divisions
Arrangements of groups

Considering the previous case, lets assume we have to divide 3p distinct objects into 3 groups of equal sizes,
so each group gets p objects. There are 3 groups, so there are 3! ways to arrange them among themselves. So
the number of ways to divide the objects is
(p + p + p)! 1

p! × p! × p! 3!

(3p)! 1
= ⋅
(p!) 3 3!

3.4. Distribution of identical objects into a specified number of groups of variable sizes

1. Empty groups are allowed


Say we have n identical objects, and we want to divide it into p groups.
★★★★★★★

We consider a row of these objects, and some 'partition elements' that we will put in between the objects to
divide them into groups. For p groups, we require (p − 1) partitions.
★|★★★|★|★★|

Now we consider the possible permutations of the whole system. We have n objects, and (p − 1) partitions,
so there are a total of (n + p − 1) entities. The number of permutations is
(n + p − 1)!

n! ⋅ (p − 1)!
Notice that this is the same as

n + p − 1 n + p − 1
( ) = ( )
p − 1 n

2. Empty groups are not allowed


We consider a row of n objects again, but this time we fill in the gaps between the objects with partitions.
There are a total of (n − 1) gaps
★__★__★__★__★__★__★

Notice that in this way, we never have a case where two partitions are next to each other, which is the same
as saying no group can have 0 objects in it.

★__★__★_|_★__★_|_★_|_★

Number of ways to put (p − 1) bars into (n − 1) gaps is


n − 1
( )
p − 1

which is the required number of distributions.

3.4.1. Division of distinct objects into a specified number of groups of variable


sizes

3.5. Distribution of distinct objects into a specified number of groups of variable sizes

1. Empty groups are allowed


If there are n objects and we have to distribute them into r groups, each object has k choices of which group
to go into. So the total number of choices is r . n

n
r

2. Empty groups are not allowed


For this, we will require the theory of inclusion and exclusion.

Say out of the r groups, we always keep the first group empty. This is basically the same as there being
(r − 1) groups, so the number of choices becomes (r − 1) .
n

Let A be the set containing the distribution of the objects keeping group 1 empty, A be the set containing
1 2

the distribution of the objects keeping group 1 empty, and so on. If one of the groups is empty, the number
of choices per object reduces by 1 and becomes (r − 1). So,
n
n(A 1 ) = n(A 2 ) =. . . = (r − 1)

The set of distributions where both the first and second set are empty is represented by A 1 ∩ A2 , and
n
n(A 1 ∩ A 2 ) = (r − 2)

because we have two less choices per object.

We want to find n(A ∪ A ∪. . . ∪A ), which is the number of ways in which at least one of the sets is empty.
1 2 r

By the principle of inclusion and exclusion, we can write it as

n
n(A 1 ∪ A 2 ∪. . . ∪A r ) = ∑ n(A i ) − ∑ n(A i ∩ A j )+. . . +(−1) ∑ n(A 1 ∩ A 2 ∩. . . ∩A r )

n
r n r
r n
⟹ n(A 1 ∪ A 2 ∪. . . ∪A r ) = r(r − 1) − ( )(r − 2) +. . . +(−1) ( )(r − (r − 1))
2 r

r n
r n r−1
r
= ( )(r − 1) − ( )(r − 2) +. . . −(−1) ( ) ⋅ 1 (last term becomes zero)
1 2 r − 1
This is the number of ways in which at least one of the sets is empty. So if we subtract this from r , we will
n

get the number of ways in which no sets are empty.

n
r n
r n r−1
r
r − ( )(r − 1) + ( )(r − 2) −. . . +(−1) ( ) ⋅ 1
1 2 r − 1

Note that this is also the coefficient of x in n!(e


n x
− 1)
r

3.6. Arrangement of distinct objects into a specified number of groups of variable sizes

1. Empty groups are allowed


Say we have n identical objects, and we want to divide it into r groups.

We consider a row of these objects, and some 'partition elements' that we will put in between the objects to
divide them into groups. For p groups, we require (r − 1) partitions.
A | B C D | E | F G |

Now we consider the possible permutations of the whole system. We have n objects, and (r − 1) partitions,
so there are a total of (n + r − 1) entities. The number of permutations in this case is
(n + r − 1)!

(r − 1)!

Notice that in the distribution of identical objects, we had a n! in the denominator to account for the n

identical objects. However in this case all the n objects are different.

2. Empty groups are not allowed


We consider a row of n objects again, but this time we fill in the gaps between the objects with partitions.
There are a total of (n − 1) gaps
★__★__★__★__★__★__★

Notice that in this way, we never have a case where two partitions are next to each other, which is the same
as saying no group can have 0 objects in it.

★__★__★_|_★__★_|_★_|_★

Number of ways to put (r − 1) bars into (n − 1) gaps is

n − 1
( )
p − 1

However this time, we also have to account for the arrangement of the n objects themselves as they are
different, which have a total of n! arrangements. So it becomes
n − 1
n! ⋅ ( )
p − 1
4. Divisors of N
We can do prime factorisation of N to represent N as the product of powers of prime numbers.
α1 α2 α3 αk
N = p1 ⋅ p2 ⋅ p3 . . . pk

2 1 2 3 1
Eg: 1337700 = 2 ⋅ 3 ⋅ 5 ⋅ 7 ⋅ 13

1337700 = 2 × 2 × 3 × 5 × 5 × 7 × 7 × 7 × 13

By choosing any number of prime factors and multiplying them, we will always get another factor of N.
This is because even after choosing any number of these prime factors, there will be at least another prime
factor left (or 1) which can be multiplied by it to get N itself.

This is similar to the selections from multiple groups of identical objects. In case of 1337700, we can
either choose the prime 7 once, twice, thrice, or not at all. So if a prime p has an exponent of α, the choices
for choosing that prime is (α + 1).

So in general, the total number of divisors of N including 1 and N is


(α 1 + 1)(α 2 + 1)(α 3 + 1). . . (α k + 1)

Note that here 1 is included as a divisor because we are including the case where we don't choose any prime
factor at all, and N is included because we are also including the case where we select all of the prime
factors at once.

Accordingly, if we want to exclude 1 or N (or both) from this number, we have to subtract 1 (or 2) from this
quantity.

4.0.1. Number of even divisors


For a number to be even, it must be possible to express it in the form 2k, i.e. as a multiple of 2. So for a
given divisor of N to be even, it must include at least one 2 in its factors. So the given condition is that 2
must be a prime factor of the given number N.

Let us consider
α1 α2 α3 αk
N = 2 ⋅ p2 ⋅ p3 . . . p
k

Now, we can choose at least one 2 from a total of α 2's in α ways. The choice of the rest of the prime
1 1

factors remains same, as we can choose to pick them or not. So the number of even divisors then becomes
α 1 ⋅ (α 2 + 1)(α 3 + 1). . . (α k + 1)

4.0.2. Number of odd divisors


For a divisor to be odd, it must not have 2 as its factor. So when choosing the prime factors of N, we can't
choose 2.

Case I: 2 is a divisor of N
N can be represented as
α1 α2 α3 αk
N = 2 ⋅ p2 ⋅ p3 . . . p
k

Since we don't want to choose 2, we can exclude it from the choices.


(α 2 + 1)(α 3 + 1). . . (α k + 1)

Case I: 2 is a divisor of N
N can be represented as
α1 α2 αk
N = p ⋅ p ...p
1 2 k

where none of these p , p . . . is 2.


1 2

Since there is no 2 choose from, we don't have to exclude anything.


(α 1 + 1)(α 2 + 1)(α 3 + 1). . . (α k + 1)

4.0.3. Sum of all divisors


Consider the number 400.
4 2
400 = 2 × 5

For all possible divisors, we can choose 2 , 2 , 2 , 2 , 2 with two's and


0 1 2 3 4 0
5 ,5 ,5
1 2
with five's. Every possible
pair from these two sets gives a unique divisor for the number 400.

x 2
0
2
1
2
2
2
3
2
4

5
0
1 2 4 8 16
5
1
5 10 20 40 80
5
2
25 50 100 200 400
Notice how this their sum is equivalent to the expansion of the following
0 1 2 3 4 0 1 2
(2 + 2 + 2 + 2 + 2 ) ⋅ (5 + 5 + 5 )

0 0 1 2 1 0 1 2 2 0 1 2
= 2 (5 + 5 + 5 ) + 2 (5 + 5 + 5 ) + 2 (5 + 5 + 5 ). . .

Which gives every possible combination, separated by + signs, which gives us exactly what we want.

In general, if
α1 α2 α3 αk
N = p1 ⋅ p2 ⋅ p3 . . . p
k

The sum of divisors S can be written as


0 1 2 α1 0 1 2 α2 0 1 2 αk
S = (p 1 + p 1 + p 1 +. . . +p )(p 2 + p 2 + p 2 +. . . +p ). . . (p k + p k + p k +. . . +p )
1 2 k

Every bracket is a sum of GP, so it can be written as


α 1 +1 α 2 +1 α k +1
p − 1 p − 1 p − 1
1 2 k
S = ⋅ ...
p1 − 1 p2 − 1 pk − 1

If we were to exclude N or 1 from this sum S, we can subtract N or 1 from S as required.

4.0.4. Resolving into product of two factors


The number of divisors or factors of N is

(α 1 + 1)(α 2 + 1)(α 3 + 1). . . (α k + 1)

Let k be a factor of N , then k


1 2 = N /k 1 is another factor of N . Notice how k can only equal k IF 1 2

k 1 = k 2 = √N

Therefore such a pair can only exist if N is a perfect square.

Case I: N is not a perfect square


If N is not a perfect square, then each factor k has a unique counterpart N /k and they cannot be equal.
Therefore, the number of factors must be even. So the number of pairs is half of the number of factors.
1
⋅ (α 1 + 1)(α 2 + 1)(α 3 + 1). . . (α k + 1)
2

Case II: N is a perfect square


If N is a perfect square, then the square root of N is the only such factor k whose counterpart N /k is equal to
itself. So when splitting the list of factors into pairs, there has to be a duplicate of one of the factors. So we
add 1 to the total number of factors before dividing it by 2.
1
⋅ ((α 1 + 1)(α 2 + 1)(α 3 + 1). . . (α k + 1) + 1)
2
4.0.5. Number of ways to resolve into coprime factors
Two numbers are said to be coprime if they do not have any common prime factor. Let N be a number
whose prime factorisation is
α1 α2 α3 αk
N = p1 ⋅ p2 ⋅ p3 . . . pk

To form two co-prime factors, they cannot share any prime factor among themselves. So if one of the factors
has p as their factor, it must include all the p 's with it, as any other p cannot be used to form the other
1 1 1

factor.

So the question becomes equivalent to the number of ways to divide p , p , . . . , p into two groups. For each
1 2 k

prime factor p, it has two choices to go in either group, and there are a total of k such primes, so the number
of distributions becomes 2 . However we don't want ordered pairs, so we have to divide by the number of
k

arrangements of the groups themselves, which is 2! = 2.


So the number of pairs (including (1, N)) becomes
k−1
2

5. Number of solutions to equations of the type x + y + z = k

5.1. Non-negative integer solutions


Consider the equation x + y + z = 10. We can represent the number 10 as a series of 1 s, and then use 2 ′

partitioning lines to divide them into 3 groups which we can call x, y, z. Then we can count the number of
possible permutations.

1 1 1 1 | 1 1 1 | 1 1 1

The number of permutations of these 12 entities is


12! 12
= ( )
10! ⋅ 2! 2

In general for x 1 , it is
+ x 2 +. . . +x r = k

k + r − 1
( )
r − 1

This is exactly the same approach we used in the distribution of identical objects into a specified number of
groups of variable sizes.

5.2. Positive integer solutions


In this case we find the number of possible places to put the partitions in the gaps between the 1 s. ′

1 _ 1 _ 1 _ 1 | 1 _ 1 _ 1 | 1 _ 1 _ 1

The number of ways to put 2 partitions in 9 gaps is

9
( )
2

In general for x 1 , it is
+ x 2 +. . . +x r = k

k − 1
( )
r − 1

This case is similar to the distribution of identical objects into a specified number of groups of variable
sizes, when the groups cannot be empty.

You might also like