Discretemaths Book
Discretemaths Book
Discretemaths Book
David A. Santos
Preface v
1 An Introduction to C++ 1
1.1 C++ Alphabet . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Comments . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.2 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.3 Keywords . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Predefined Types . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 Notation for Types . . . . . . . . . . . . . . . . . . . 5
1.3 Variables and Constants . . . . . . . . . . . . . . . . . . . . 7
1.3.1 Scalar Types . . . . . . . . . . . . . . . . . . . . . . 7
1.3.2 Aggregate Types . . . . . . . . . . . . . . . . . . . . 9
1.3.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4 Input and Output . . . . . . . . . . . . . . . . . . . . . . . . 14
1.5 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.5.1 Unary Operators . . . . . . . . . . . . . . . . . . . . 16
1.5.2 Arithmetical Binary Operators . . . . . . . . . . . . . 16
1.5.3 Assignment Operators . . . . . . . . . . . . . . . . . 19
1.5.4 Relational Operators . . . . . . . . . . . . . . . . . . 24
1.5.5 Logical Operators . . . . . . . . . . . . . . . . . . . 24
1.5.6 Conditional Operator . . . . . . . . . . . . . . . . . . 25
1.5.7 Comma Operator . . . . . . . . . . . . . . . . . . . . 26
1.6 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.7 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
1.7.1 main() Function . . . . . . . . . . . . . . . . . . . . 31
iii
iv CONTENTS
2 Essential Techniques 1
2.1 Reductio ad Absurdum . . . . . . . . . . . . . . . . . . . . . 1
2.2 Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Inclusion-Exclusion . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Parity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3 Counting 19
3.1 Introductory Problems . . . . . . . . . . . . . . . . . . . . . 19
3.2 Two Basic Counting Principles . . . . . . . . . . . . . . . . 23
3.3 Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.4 Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.5 Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.6 Combinatorial Identities . . . . . . . . . . . . . . . . . . . . 38
3.7 The Binomial Theorem . . . . . . . . . . . . . . . . . . . . . 40
3.8 Multinomial Theorem . . . . . . . . . . . . . . . . . . . . . . 57
4 Arithmetic 61
4.1 Division Algorithm . . . . . . . . . . . . . . . . . . . . . . . 61
4.2 The Decimal Scale . . . . . . . . . . . . . . . . . . . . . . . 66
4.3 Non-decimal Scales . . . . . . . . . . . . . . . . . . . . . . 73
4.4 Well-Ordering Principle . . . . . . . . . . . . . . . . . . . . 77
4.5 Mathematical Induction . . . . . . . . . . . . . . . . . . . . 80
4.6 Congruences . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.7 Miscellaneous Problems with Integers . . . . . . . . . . . . 94
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G
H I J K L M N O P Q R S T U V W X Y Z
+ - * / % \ " ’ # , . ; : ! ? ( ) [ ] { } < > ^ &
~ | _ 0 1 2 3 4 5 6 7 8 9
The C++ tokens are: the keywords, the identifiers, the constants, the
string-literals, the operators, and the punctuators, which will be defined
shortly.
! White space does not belong to the C++ alphabet. Whitespace serves
to indicate where tokens start and end: beyond this, any surplus of whites-
pace is discarded.
1
2 Chapter 1
1.1.1 Comments
Comments in C++ may occur in one of two forms. They may begin with a
double slash and end in the same line where they started, as in
will produce a compiler error. This is because the compiler matches the first
/∗ with the first ∗/ that it encounters, and so the second /∗ is viewed as part
of the outer comment.
[ ] ( ) { } , ; : ... * = #
C++ Alphabet 3
1.1.2 Blocks
6 Definition A block is a grouping delimited by a left brace { and a match-
ing right brace }. Any two blocks may be either disjoint or nested.
8 Example In the following example, blocks II and III are disjoint, and both
are nested into block I.
{// opens block I ................
{// opens block II
.................
}// closes block II
{// opens block III
..................
}// closes block III
................. }// closes block I
1.1.3 Keywords
9 Definition A C++ keyword is a string of characters having a predeter-
mined meaning in the C++ language.
• the type bool. This type is the boolean type, which can only assume
the values true or false.
• the type char. This is the character type. Used to represent single
characters like those forming the C++ alphabet.
• the type string. This is the string type. Used to represent strings of
characters.
• the type int. This is the integer type. The range of the integers is
machine-dependent, but we can at least assure ourselves that inte-
gers in the interval [−231 ; 231 − 1] will be represented.
• the type float. This is the real number type. Its range is machine-
dependent, but we can at least assure ourselves that the interval
[3.4 × 10−38 ; 3.4 × 1038 ] will be represented.
• the type double. These are real numbers with double precision. Nor-
mally in the range [1.7 × 10−308 ; 1.7 × 10308 ].
The range of the int type can be modified by the keywords long or short.
For example, in some machines a long int is in the range [−263 ; 263 − 1].
To indicate the compiler that we are using a real floating point (decimal)
number we use a decimal point, the ten digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
the letters e or E to indicate a power of 10, and an optional sign {+, −}.
! The compiler distinguishes between, say, “7” (no decimal point) and
“7.” (with a decimal point). “7” is an integer, “7.” is a floating point number.
• ’\r’ denotes the carriage return (return to the beginning of the present
line) character,
To indicate the compiler that we are using a string type, we enclose the
string in double quotes.
14 Example The following are string types ”A” ”Anthony” ”I break for
camels!”
we need to type
”\”What is your name silly\?\”,\nsaid the idiot.\n”
Notice that since C++ is case sensitive, the identifiers PI and Pi are dis-
tinct.
Variables can be modified during the life programme. The type of the
variable specifies how much memory is allocated to the variable.
C++ allows multiple variables of the same type to be declared on one line
by means of a comma. For instance, the code
int var_a; int var_b; double var_c;
int var_a;
int var_a, var_b; //ERROR multiple declaration of var_a
double var_b //ERROR multiple declaration of var_b
! C++ does not check for array bounds. Invoking the non-existent “ele-
ments” a[3], a[4], say, of the array in example 24 will result in an error.
! We may not omit the size of the array if we are simply declaring the
array. Thus
int a[]; //ERROR
will result in error. The compiler does not know how much space to allocate
to the array.
! If we initialise all the elements of the array, we may omit the internal
braces. Thus the above initialisation is equivalent to
int b[3][5] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15};
31 Example If
int t[2][3] = {{1, 2}, {3}};
If the braces delimiting the rows are omitted, a totally different answer may
be obtained.
32 Example In
int t[2][3] = {1, 2, 3};
type_N identifier_N;
}s_instance_1, s_instance_2, ..., s_instance_M;
1.3.3 Constants
we type
cout << ”Camels of the World: Unite!”;
we type
cout << ”Camels of the World:\nUnite!”;
is
The sum of a + b 6is.
Notice that there is no space between the “6” and the “i”. Notice that
we did not need quotes around a +b—, since we wanted the computer to
calculate this sum, rather than to output the string a + b.
errors.
cout << ”Camels of the World: //ERROR.
Unite!”; //Unmatched double quote.
asks the user for an integer variable to be input (which we enter through,
say, the keyboard, and then press ENTER), and then for a string of charac-
ters to be input. The computer does not know that data has been entered
until the ENTER key is pressed.
will cause a compiler error. The variable b is called for input, but it has not
been declared.
1.5 Operators
48 Definition An operator is a character, or string of characters, used to
perform an action on some entities. These entities are called the operands.
16 Chapter 1
There are 55 operators in ISO C++, with 18 layers of precedence (17 is the
highest level of precedence, 0 the lowest). Table 1.2 lists some of them.
will print
a = 3 b = 2.86
print?
and
17%4 ∗ 2 = (17%4) ∗ 2 = 1 ∗ 2 = 2.
Operators 19
will print
a = 4. a = 23 now.
will print
a = 4. a = 23. a = 45.
! The assignment operator = does not test for equality. To test for equal-
ity, C++ uses the equality comparison operator ==.
a = a + b;
b = a - b;
a = a - b;
int i = 3, j = 3, k = 3;
int a = 8;
Operators 23
a *= 9;
a++;
Solution: First the value of a is increased to 9, and upon leaving the state-
ment is increased to 10. Thus a == 10.
int x = 1, y = 4, z, w, a;
z = x < y ;
w = (x + 5) <= y;
a = y != 5;
!1 gives 0 !0 gives 1
The logical AND operator && gives output according to the following rules:
C++’s only ternary operator is the conditional operator ?: which has the
following syntax
and evaluates as follows. test is evaluated first. If it is true, then the whole
expression becomes alternative_1, and alternative_2 is not evaluated
at all. If test is false, alternative_1 is skipped, and the whole expression
becomes alternative_2.
int a = 3, b = 6, c;
c = (a==b) ? (a + 1) : (b - 8);
c becomes -2, since a==b is false and so the conditional expression as-
sumes the second alternative b-8.
int a = 1, b;
b = (a += 1, a += 2, a + 5);
the comma operator first evaluates a+=1 which makes a == 2. The next
expression a+=2 is evaluated and so a == 4. Finally, the last expression
a + 5 is evaluated becoming a + 5 == 9. Hence b == 9.
1.6 Pointers
C++ allows the address of a variable to be accessed through the contents
of another variable.
This creates a variable, identifier, which holds the address (“points to”)
of another variable of the same type.
We will prefer the first way of declaring pointers, as the latter two forms
suggests to some, quite erroneously, that the * distributes over the
identifiers. In fact, if more than one pointer is declared on the same
statement, each identifier must be given an *. For example, in
type *identifier_1, identifier_2; type *identifier_3,
*identifier_4;
! Memory locations are allocated at compile time, and thus are fixed.
Therefore, a variable which is not declared as a pointer cannot be given the
address of another variable, since a variable may be modified.
Solution: p has not been initialised, it is not pointing to any variable, and
hence, it cannot modify the contents of this variable by inserting the value
2.2.
1.7 Functions
Fragments of code that need to be recycled can be put into functions.
In mathematics, a function is composed of 5 elements: (1) a name, (2) a
rule, (3) the name of a typical input, (4) a domain, and (5) a target set.
Thus a function has the form
A → B
f: ,
x 7→ f(x)
target_set f(domain).
The domains and target set must come from an available type.
90 Example Here is a function which prompts the user to enter the radius
of a circle
void prompt_radius()
{
cout << ”Please enter the radius of a circle: ”;
}
92 Example Here is a function which finds the area of a circle upon been
fed its radius
double Area_of_Circle(double radius)
{
const double PI = 3.14159;
return PI*radius*radius;
}
93 Example Here is a function which prints the area of a circle upon been
fed with it.
void print_area_of_circle(double Area)
{
cout << ”Area of circle is ” << Area;
}
body
return 0;
}
The value 0 returned by main(){} means that everything has gone well.
The optional programme parameters argc and *argv[] are run from the
command line.
• We can declare the functions before main(){} and then define them
after main(){}.
For the (tiny) C++ programmes that we will see in these notes we will
prefer the first style of writing programmes.
98 Example The scope rules seen in example 65 hold within the bodies of
functions. The fragment
int a = 17, b = -3; int foo(int c)
{
int b;
b = 2*c + a;
cout << ”II: within foo, a = ” << a << ”, b = ”
<< b << ”, and c = ” << c << ’\n’;
return b;
}
34 Chapter 1
void faa(void)
{
int c = b*a;
cout << ”III: within faa, a = ” << a << ”, b = ”
<< b << ”, and c = ” << c << ’\n’;
}
int main() { int a = -5, c = 7; a = foo(c); cout <<”I: within
main, a = ” << a << ”, b = ”
<< b << ”, and c = ” << c << ’\n’;
faa(); return 0; }
will print
II: within foo, a = 17, b = 31, and c = 7 I: within main,
a = 31, b = -3, and c = 7 III: within faa, a = 17, b = -3, and c =
-51
will print f(i) = 6 and i = 3, that is, even though the value of i suffered
changes within f(), it was not altered by f().
We see then that simply passing the value of a variable to a function does
not change the contents of the variable. In order to change the contents
of the variable, we must pass the address of the variable rather than it
contents. This is called passing by reference.
will print
Printing I in main, a = 18 Within foo, a = 5 Printing II
in main, a = 18 Within faa, a = 5 Printing III in main, a = 5
102 Example The code following code fragment contains two functions
which purportedly exchange the values of two variables.
int swap_bad(int x, int y) {
int temp;
temp = x;
x = y;
y = temp;
36 Chapter 1
will print
I: In main first_var = 1 and second_var = 2 Within
swap_bad first_var = 2 and second_var = 1 II: In main first_var =
1 and second_var = 2 Within swap_good first_var = 2 and second_var
= 1 III: In main first_var = 2 and second_var = 1
if{}else{} Statement 37
will not print anything. a=0 is not a test, it is an assignment, and so this is
equivalent to if(0). The programmer perhaps meant to write
int a = 0;
if (a==0)
cout << ”Aha!”;
106 Example The logical AND and the logical OR have a short-circuiting
property that it is at times rather useful. If the first argument in a && b is
0, then b is not evaluated and the output of a && b is 0 no matter what b
might be. Similarly, if the first argument in a || b is 1, then b is not
evaluated and the output of a || b is 1 no matter what b might be. For
example, the programme segment
int a = -3, b = 0;
if ((a + 3) && a/b)
will not cause division by 0, as the test will be short-circuited because a+3
evaluates to 0.
107 Example Care must be exercised with the grouping. C++ ignores
indentation. The fragment
int a = 4, b = 5;
if (a < 3)
b = 7;
a = a + b;
cout << ”a = ” << a;
if{}else{} Statement 39
will print a = 4.
108 Example What is the value of c at the end of the following code
fragment?
int a=0,b=1,c=2;
if(a) if(b) c=3;
else c=4;
Solution: First notice that both ifs are in the same block and hence the
else belongs to the nearest if, that is, to if(c) k=3;. Thus this fragment
can be written as
int a=0,b=1,c=2;
if(a) {if(b) c=3; else c=4;}
Now the test in if(a) is false, hence control is passed after the brace.
This means that c has not changed at all, and hence c==2.
109 Example What is the value of c at the end of the following code
fragment?
int a=0,b=1,c=2;
if(a) {if(b) c=3;}
else c=4;
40 Chapter 1
Solution: In this case the else does not to belong to the same block as
if(b), but it is in the same block as if(a), and so it belongs to it. The
test in if(a) evaluates to false and hence control is passed to the else.
This makes c==4.
Here condition must be of int or char type, or a related type that can be
converted into one of these two. The cases must all be different. If one of
the cases is met, its option is executed and the control is passed to the
closing brace. If break; does not appear in a case, the next case will be
executed. The default statement is optional, and only one default
statement is allowed.
will print a = 0.
default: a = 27;
}
cout << ”a = ” << a;
Any of the parts in a for loop may be omitted. Here we start with the initial
condition. It if meets the test condition, the body of the loop is executed
and then the loop changes. This procedure goes on until the test
condition evaluates to false.
int a = 2, b = 5, i;
for(i = 3; i < 8; i += 2, b--)
{//opens body of for
a += b;
cout << ”a is ”
<< a
<< ”, b is ”
<< b << ”, and i is ”
<< i << ’\n’;
}//closes body of for
will print
a is 7, b is 5, and i is 3 a is 11, b is 4, and i is 5 a
is 14, b is 3, and i is 7
We start with i == 3. We test whether i < 8, which is true. The body of
the loop is executed and we get a == 7. The loop changes are executed
and we get i == 5 and b == 4. We test again i < 8, which is true. The
body of the loop is executed and we get a == 11. The loop changes are
executed and we get i == 7 and b == 3. We test whether i < 8, which is
true. The body of the loop is executed and we get a == 14. The loop
changes are executed and we get i == 9 and b == 2. We test whether
i < 8, which is false. We stop.
119 Example The code in example 118 could have been written as
int a = 2, b = 5;
for(int i = 3; i < 8; i += 2, b--)
{//opens body of for
a += b;
cout << ”a is ”
<< a
44 Chapter 1
<< ”, b is ”
<< b << ”, and i is ”
<< i << ’\n’;
}//closes body of for
Since these numbers grow rather fast and memory space is scarce, my
system is only able to calculate up to 16! accurately.
The commands in the body of the loop will be executed as long as the
test evaluates to true.
will print
a is 9 and b is 5 a is 8 and b is 6 a is 7 and b is 7
! Had we written
int a = 10, b = 3;
while(a - b)
{
a--; b++;
cout << ”a is ” << a << ” and b is ” << b << ’\n’;
}
<< ” reversed is ”
<< reverse(input_var);
prompt_user();
input_var = read_input();
}//closes while
return 0;
} //closes main
125 Example Recall that a positive integer p > 1 is a prime if its only
positive integral divisors are 1 and p itself. The series of primes goes thus
like 2, 3, 5, 7, 11, 13, 17, 19, 23, . . .. Write a programme determining whether
a given integer is a prime.
Solution: Our input will only accept positive integers. Observe that 2 is
the only even prime. Thus we test the input integer to see whether it is 1 (
which is neither prime nor composite), 2 (which is a prime), or an even
number greater than 2 (in which case the number is composite). If neither
of these applies, then the number, call it p, is odd and greater than 1. We
then divide p by every odd integer up to p − 2. If p is not divisible by any
of these integers, then p must be prime. Observe that this algorithm
makes about p/2 tests. In the Number Theory Chapter we will see that
√
the same algorithm used here only requires about p tests.
//rudimentary_primality.cpp
#include <iostream> using namespace std; void prompt_user()
{//opens prompt_user
cout << ”\nLet\’s test the primality of a positive integer.\n”;
cout << ”Enter a positive integer.\n”;
cout << ”Enter 0 or a negative integer to stop: ”;
}//closes prompt_user int read_input() {//opens read_input
48 Chapter 1
int a;
cin >> a;
if(a <=0){cout << ”You have decided to quit. Good Bye.\n”;
return 0;}
else if (a==1) {cout << a
<< ” is neither prime nor composite.\n”;
return a;}
else if (a==2) {cout << a << ” is prime.\n”; return a;}
else if (a%2 == 0) {cout << a << ” is an even
number.\n” ; return a; }
else return a;
}//closes read_input void primality_test(int p) {//opens
primality_test
if(p%2!=0) {// opens if(p%2!=0)
bool flag = true;
for(int i=3; i < p; i += 2) if (p%i ==0) {flag = false;
break;}
if (flag) cout << p << ” is prime.\n” << ’\n’;
else cout << p
<< ” is not prime.”
<< ” Its smallest prime factor is ”
<< i << ’\n’;
}//closes if(p%2!=0)
}//closes primality_test int main() {//opens main prompt_user();
int input_var = read_input(); while(input_var)
{//opens while
primality_test(input_var);
prompt_user();
input_var = read_input();
}//closes while
return 0; }//closes main
int main()
{//opens main
return 0;
}//closes main
simulates the game “PAPER, ROCK, SCISSORS.” The user plays against
the computer, which prompts him for an option of these three and
produces its random choice (the computer does not cheat!). The function
rand() resides in the header file cstdlib and produces a pseudo-random
integer. In order to further randomise the computer choice, we put a
time-dependent seed via the instruction srand(time(NULL));. Since we
only have three choices, we reduce num_equiv_comp modulo 3 to produce
a random integer in the set {0, 1, 2}.
127 Example Write a programme where the user inputs three numerical
real number coefficients a, b, and c and then solves the equation
ax2 + bx + c. If the equation is quadratic, it must provide for the cases
Examples of Full Programmes 51
when the roots are complex. If the equation is linear, it must tell the user
that it is a linear equation. If the equation is degenerate, it must tell the
user so.
<< ” + i”
<< sqrt(-discriminant)/(2*a);
cout << ” and x_2 = ”
<< -b/(2*a)
<< ” - i”
<< sqrt(-discriminant)/(2*a) << ’\n’;
} //closes complex
else
{ //opens real
cout << ”\nIt has two real roots: x_1 = ”
<< (-b + sqrt(discriminant))/(2*a);
cout << ” and x_2 = ”
<< (-b - sqrt(discriminant))/(2*a) <<
’\n’ ;
} //closes real
} //closes quadratic
return 0;
} //closes main
We had to recur to the header file cmath which contains the square root
function. Observe that since we had to use several blocks, we
commented each brace. This is a good practice in general.
128 Example Write a programme where the user inputs three real
numbers a, b, and c and tells whether these numbers form the lengths of
a triangle. If a triangle can be formed with the given input, then it will find
its area by means of Heron’s formula
where
a+b+c
s=
2
is the semi-perimeter of the triangle. If at a given point the user enters a
non-positive number, the programme should stop then.
#include <cmath>
using namespace std;
int main()
{ //opens main
double a, b, c;
cout << ”Enter a first length: ”;
cin >> a;
if (a<=0) {cout << ”Bad input.\n”; exit(1);}
cout << ”\nEnter a second length: ”;
cin >> b;
if (b<=0) {cout << ”Bad input.\n”; exit(1);}
cout << ”\nEnter a third length: ”;
cin >> c;
if (b<=0) {cout << ”Bad input.\n”; exit(1);}
if (a + b <= c || a + c <= b || b + c <= a)
cout << ”Sorry, these don’t form a triangle.\n”;
else
{//opens area computation
double s = (a + b + c)/2;
cout << ”The area of the triangle is ”
<< sqrt(s*(s - a)*(s - b)*(s - c))
<< ” square units.\n”;
} //closes area computation
return 0;
} //closes main
int main()
{ //opens main
bool locker[101];
//setting every locker open == true.
for(int i = 1; i <= 100; i++) locker[i] = true;
for(int j = 2; j <=100; j++)
{for(int k = 1; k <= 100; k++) if(k % j == 0) locker[k] =
!locker[k]; }
for(int l = 1; l <= 100 ; l++ ) if(locker[l]) cout << ”Locker ”
<< l << ” remains open.\n ”;
return 0;
} //closes main
56 Chapter 1
Chapter 2
Essential Techniques
√ 1
131 Example Show, without using a calculator, that 6 − 35 < .
10
√ 1 1 √ √
Solution: Assume that 6 − 35 ≥. Then 6 − ≥ 35 or 59 ≥ 10 35.
10 10
Squaring both sides we obtain 3841 ≥ 3500, which is clearly nonsense.
√ 1
Thus it must be the case that 6 − 35 < .
10
is even.
Solution: First observe that the sum of an odd number of odd integers is
odd. It is enough to prove that some difference ak − k is even. Assume
1
2 Chapter 2
Solution: For this proof, we will accept as fact that any positive integer
greater than 1 can be factorised uniquely as the product of primes (up to
the order of the factors).
√ a
Assume that 2 = , with positive integers a, b. This yields 2b2 = a2 .
b
Now both a2 and b2 have an even number of prime factors. So 2b2 has an
odd numbers of primes in its factorisation and a2 has an even number of
primes in its factorisation. This is a contradiction.
134 Example Let a, b be real numbers and assume that for all numbers
> 0 the following inequality holds:
a < b + .
Prove that a ≤ b.
a−b
Solution: Assume contrariwise that a > b. Hence > 0. Since the
2
inequality a < b + holds for every > 0 in particular it holds for
a−b
= . This implies that
2
a−b
a<b+ or a < b.
2
Thus starting with the assumption that a > b we reach the incompatible
conclusion that a < b. The original assumption must be wrong. We
therefore conclude that a ≤ b.
135 Example Show that there are infinitely many prime numbers.
Reductio ad Absurdum 3
Solution: We need to assume for this proof that any integer greater than 1
is either a prime or a product of primes. The following beautiful proof
goes back to Euclid.
Assume that {p1 , p2 , . . . , pn } is a list that exhauts all the primes. Consider
the numberN = p1 p2 · · · pn + 1. This is a positive integer, clearly greater
than 1. Observe that none of the primes on the list {p1 , p2 , . . . , pn } divides
N, since division by any of these primes leaves a remainder of 1. Since N
is larger than any of the primes on this list, it is either a prime or divisible
by a prime outside this list. Thus we have shown that the assumption that
any finite list of primes leads to the existence of a prime outside this list.
This implies that the number of primes is infinite.
136 Example Let n > 1 be a composite integer. Prove that n has a prime
factor p ≤ n.
Ad Pleniorem Scientiam
137 Problem The product of 34 integers is equal to 1. Show that their sum
cannot be 0.
√
142 Problem Let 0 < α < 1. Prove that α > α.
147 Example (P UTNAM 1978) Let A be any set of twenty integers chosen
from the arithmetic progression 1, 4, . . . , 100. Prove that there must be two
distinct integers in A whose sum is 104.
148 Example Show that amongst any seven distinct positive integers not
exceeding 126, one can find two of them, say a and b, which satisfy
b < a ≤ 2b.
Solution: Split the numbers {1, 2, 3, . . . , 126} into the six sets
{1, 2}, {3, 4, 5, 6}, {7, 8, . . . , 13, 14}, {15, 16, . . . , 29, 30},
{31, 32, . . . , 61, 62} and {63, 64, . . . , 126}.
By the Pigeonhole Principle, two of the seven numbers must lie in one of
the six sets, and obviously, any such two will satisfy the stated inequality.
149 Example No matter which fifty five integers may be selected from
{1, 2, . . . , 100},
prove that one must select some two that differ by 10.
and if n + 1 integers are chosen from this, there must be two that belong
to the same group.
So now group the one hundred integers as follows:
150 Example (A HSME 1994) Label one disc “1”, two discs “2”, three discs
“3”, . . . , fifty discs ‘‘50”. Put these 1 + 2 + 3 + · · · + 50 = 1275 labeled discs
in a box. Discs are then drawn from the box at random without
replacement. What is the minimum number of discs that must me drawn
in order to guarantee drawing at least ten discs with the same label?
the five remaining that correspond with Eric in one of the topics, say topic
II. If amongst these three there is a pair that corresponds with each other
on topic II, then Eric and this pair correspond on topic II, and we are
done. Otherwise, these three people only correspond with one another
on topic III, and we are done again.
152 Example Given any set of ten natural numbers between 1 and 99
inclusive, prove that there are two disjoint nonempty subsets of the set
with equal sums of their elements.
Solution: There are 210 − 1 = 1023 non-empty subsets that one can form
with a given 10-element set. To each of these subsets we associate the
sum of its elements. The maximum value that any such sum can achieve
is 90 + 91 + · · · + 99 = 945 < 1023. Therefore, there must be at least two
different subsets that have the same sum.
153 Example Given any 9 integers whose prime factors lie in the set
{3, 7, 11} prove that there must be two whose product is a square.
Ad Pleniorem Scientiam
154 Problem Prove that among n integers, there are always two whose
difference is always divisible by n.
155 Problem (A HSME 1991) A circular table has exactly sixty chairs
around it. There are N people seated at this table in such a way that the
next person to be seated must sit next to someone. What is the smallest
possible value of N?
8 Chapter 2
Answer: 20.
156 Problem Show that if any five points are all in, or √
on, a square of side
1, then some pair of them will be at most at distance 2/2.
158 Problem Show that in any sum of nonnegative real numbers there is
always one number which is at least the average of the numbers and that
there is always one member that it is at most the average of the numbers.
159 Problem We call a set “sum free” if no two elements of the set add up
to a third element of the set. What is the maximum size of a sum free
subset of {1, 2, . . . , 2n − 1}.
160 Problem (M MPC 1992) Suppose that the letters of the English
alphabet are listed in an arbitrary order.
3. Suppose that all the letters are arranged in a circle. Prove that there
must be five consecutive consonants.
161 Problem (S TANFORD 1953) Bob has ten pockets and forty four silver
dollars. He wants to put his dollars into his pockets so distributed that
each pocket contains a different number of dollars.
1. Can he do so?
Pigeonhole Principle 9
163 Problem No matter which fifty five integers may be selected from
{1, 2, . . . , 100},
prove that you must select some two that differ by 9, some two that differ
by 10, some two that differ by 12, and some two that differ by 13, but that
you need not have any two that differ by 11.
164 Problem Let mn + 1 different real numbers be given. Prove that there
is either an increasing sequence with at least n + 1 members, or a
decreasing sequence with at least m + 1 members.
165 Problem If the points of the plane are coloured with three colours,
show that there will always exist two points of the same colour which are
one unit apart.
166 Problem Show that if the points of the plane are coloured with two
colours, there will always exist an equilateral triangle with all its vertices of
the same colour. There is, however, a colouring of the points of the plane
with two colours for which no equilateral triangle of side 1 has all its
vertices of the same colour.
168 Problem (U SAMO 1982) In a party with 1982 persons, amongst any
group of four there is at least one person who knows each of the other
three. What is the minimum number of people in the party who know
everyone else?
169 Problem (U SAMO 1985) There are n people at a party. Prove that
there are two people such that, of the remaining n − 2 people, there are
at least [n/2] − 1 of them, each of whom knows both or else knows
neither of the two. Assume that “knowing” is a symmetrical relationship.
2.3 Inclusion-Exclusion
In the Venn diagram below, we mark by R1 the number of elements which
are simultaneously in both sets (i.e., in A ∩ B), by R2 the number of
elements which are in AA but not in B (i.e., in A \ B),
B and by R3 the number
Let |X| denote the number of elements of the set X. Now clearly
R1 + R2 + R3 = |A ∪ B|. This gives the Inclusion-Exclusion Formula for two
sets
[ \
(2.1) |A B| = |A| + |B| − |A B|
Inclusion-Exclusion 11
Solution: Let A denote the set of smokers and B the set of chewers. Then
meaning that there are 34 people that either smoke or chew (or possibly
both). Therefore the number of people that neither smoke nor chew is
40 − 34 = 6.
Aliter: We fill up the Venn diagram below as follows. Since |A ∩ B| = 8, we
put an 10 in the intersection. Then we put a 28 − 10 = 18 in the part that
A does not overlap B and a 16 − 10 = 6 in the part of B that does not
overlap A. We have accounted for 10 + 186+ 6 = 34 people that are in at
least one of the set. The remaining
A 40 − 34 B= 6 are outside the sets.$.4in]
18 8 6
172 Definition We use φ(n), the Euler phi function to denote the number
of integers k, 1 ≤ k ≤ n which are relatively prime to n.
173 Example How many integer between 1 and 1000 inclusive, do not
share a common factor with 1000, that is, are relatively prime to 1000?
We define φ(1) = 1. Let n > 1 with prime factorisation n = pα1 1 pα2 2 · · · pαk k .
Then it is possible to show by a generalised Inclusion-Exclusion
argument that
φ(n) = n 1 − p11 1 − p12 · · · 1 − p1k
(2.2)
= (pα1 1 − p1α1 −1 )(pα2 2 − pα2 2 −1 ) · · · (pαk k − pαk k −1 )
174 Example In how many ways can one decompose the set
{1, 2, 3, . . . , 100} into subsets A, B, C satisfying
Solution: The conditions of the problem stipulate that both the region
outside the circles in diagram 1.2 and R3 will be empty. We are thus left
with 6 regions to distribute 100 numbers. To each of the 100 numbers we
may thus assign one of 6 labels. The number of sets thus required is 6100 .
Inclusion-Exclusion 13
175 Example How many integers between 1 and 600 inclusive are not
divisible by neither 3, nor 5, nor 7?
Solution: Let Ak denote the numbers in [1, 600] which are divisible by
k = 3, 5, 7. Then
|A3 | = b 600
3
c = 200,
600
|A5 | = b 5 c = 120,
|A7 | = b 600
7
c = 85,
600
|A15 | = b 15 c = 40
|A21 | = b 600
21
c = 28
600
|A35 | = b 35 c = 17
600
|A105 | = b 105 c = 5
By Inclusion-Exclusion there are 200 + 120 + 85 − 28 − 21 − 17 + 5 = 325
integers in [1, 600] divisible by at least one of 3, 5, or 7. Those not
divisible by these numbers are a total of 600 − 325 = 275.
Solution: Let A be the set of all English speakers, B the set of Spanish
speakers and C the set of French speakers in our group. We fill up the
following Venn diagram successively. In the intersection of all three we
put 8. In the region common to A and B which is not filled up we put
5 − 2 = 3. In the region common to A and C which is not already filled up
we put 5 − 3 = 2. In the region common to B and C which is not already
filled up, we put 7 − 3 = 4. In the remaining part of A we put
8 − 2 − 3 − 2 = 1, in the remaining part of B we put 12 − 4 − 3 − 2 = 3, and
in the remaining part of C we put 10 − 2 − 3 − 4 = 1. Each of the mutually
disjoint regions comprise a total of 1 + 2 + 3 + 4 + 1 + 2 + 3 = 16 persons.
Those outside these three sets are then 30 − 16 = 14.$.4in]
Ad Pleniorem Scientiam
177 Problem How many integers between 1 and 3012 are divisible by 5 or
7 but not by both numbers?
14 Chapter 2
178 Problem Would you believe a market investigator who reports that of
1000 people, 816 like candy, 723 ice cream, 645 cake, while 562 like both
candy and ice cream, 463 like both candy and cake, 470 like both ice
cream and cake, while 310 like all three?
179 Problem (Lewis Carroll) In a very hotly fought battle, at least 70% of
the combatants lost an eye, at least 75% an ear, at least 80% an arm, and
at least 85% a leg. What can be said about the percentage that lost all
four members?
182 Problem How many integers between 1 and 49000 inclusive are not
divisible by 3, 5 or 7?
183 Problem How many integers from 1 to 1 000 000 inclusive are neither
perfect squares, perfect cubes, nor perfect fourth powers?
x + y = min(x, y) + max(x, y)
Parity 15
2.4 Parity
187 Example Two diametrically opposite corners of a chess board are
deleted. Show that it is impossible to tile the remaining 62 squares with 31
dominoes.
Solution: Each domino covers one red square and one black squares.
But diametrically opposite corners are of the same colour, hence this
tiling is impossible.
188 Example All the dominoes in a set are laid out in a chain according to
the rules of the game. If one end of the chain is a 6, what is at the other
end?
Solution: At the other end there must be a 6 also. Each number of spots
must occur in a pair, so that we may put them end to end. Since there are
eight 6’s, this last 6 pairs off with the one at the beginning of the chain.
189 Definition The midpoint of the line joining (x, y) to (x1 , y1 ) is the point
x + x1 y + y 1
, .
2 2
191 Definition A lattice point (m, n) on the plane is one having integer
coordinates.
16 Chapter 2
192 Example Five lattice points are chosen at random. Prove that one
can always find two so that the midpoint of the line joining them is also a
lattice point.
Solution: There are four parity patterns: (even, even), (even, odd), (odd,
odd), (odd, even). By the Pigeonhole Principle among five lattice points
there must be two having the same parity pattern. Choose these two. It is
clear that their midpoint is an integer.
For the following examples we will need to know the names of the
following tetrominoes. $.4in]
L-tetromino T- Straight- Skew-
$.4in] tetromino$.4in]tetromino$.4in]
tetromino$.4in]
Show that an 8 × 8 chessboard cannot be tiles with 15 straight
tetrominoes and one L-tetromino.
Ad Pleniorem Scientiam
193 Problem Twenty-five boys and girls are seated at a round table. Show
that both neighbours of at least one student are girls.
194 Problem A closed path is made of 2001 line segments. Prove that
there is no line, not passing through a vertex of the path, intersecting
each of the segments of the path.
Solution: Points 16, 17, . . . , 48 are 33 in total and are on the same side of
the diameter joining 15 to 49. For each of these points there is a
corresponding diametrically opposite point. There are thus a total of
2 · 33 + 2 = 68 points.
199 Example How many factors of 295 are larger than 1, 000, 000?
200 Example How many positive divisors does 28 39 52 have? What is the
sum of these divisors?
19
20 Chapter 3
(1 + 2 + 22 + · · · + 28 )(1 + 3 + 32 + · · · + 39 )(1 + 5 + 52 )
each factor of 28 39 52 appears and only the factors of this number appear.
There are then, as many factors as terms in this product. This means that
there are (1 + 8)(1 + 9)(1 + 3) = 320 factors.
The sum of the divisors of this number may be obtained by adding up
each geometric series in parentheses. The desired sum is then
29 − 1 310 − 1 53 − 1
· · = 467689684.
2−1 3−1 5−1
The argument works in general. If n = pa1 1 · pa2 2 · · · pas s , where the p’s are
distinct primes and if d(n), σ(n) denote, respectively, the nunber of
positive divisors of n and the sum of these positive divisors of n, then
and
201 Example A locker room has 100 lockers. Initially, all the lockers are
closed. Person 1 enters, and opens all the lockers which are even and
then leaves. Person 2 enters and opens all the lockers that have numbers
which are multiples of 3, closing those lockers which were already
opened, and then leaves. Person 3 enters and changes the status of the
lockers (from opened to closed and viceversa) on all the lockers which
have numbers which are multiples of 4. This goes on till Person 99 enters
and changes the status of locker 100. Which lockers remained closed?
202 Example How many positive integers have (i) 2 digits? (ii) 3 digits?
(iii) 4 digits?
203 Example To write a book 1890 digits were utilised. How many pages
does the book have?
Solution: A total of
1 · 9 + 2 · 90 = 189
digits are used to write pages 1 to 99, inclusive. We have of
1890 − 189 = 1701 digits at our disposition which is enough for
1701/3 = 567 extra pages (starting from page 100). The book has
99 + 567 = 666 pages.
204 Example All the natural numbers, starting with 1, are listed
consecutively
123456789101112131415161718192021 . . .
Which digit occupies the 1002nd place?
205 Example (A HSME 1994) When n standard six-sided dice are rolled,
the probability of obtaining a sum of 1994 is greater than zero and is the
same as the probability of obtaining a sum of S. What is the smallest
possible value of S?
Solution: Since the probability of obtaining the sum 1994 is positive, there
1994
are n ≥ b c = 333 dice. Let x1 + x2 + · · · + xn = 1994 be the sum of
6
the faces of the n dice adding to 1994. We are given that
(7 − x1 ) + (7 − x2 ) + · · · + (7 − xn ) = S
This gives (x, y) = (1, 93) or (x, y) = (3, 31). In the first case
is in the desired range for 1 ≤ a ≤ 465. The two sets of four-tuples are
disjoint, and so the sought number is 870.
Ad Pleniorem Scientiam
Two Basic Counting Principles 23
208 Problem The integers from 1 to 1000 are written on a circle. Starting
with 1, each 15th is marked (that is, 1, 16, 31, etc. are marked). This
operation is repeated until a number is marked again. How many integers
remain unmarked
Answer: 800
Answer: 4
210 Problem Four comrades are racing down a dusty staircase. Oli goes
down two steps at a time, Gooh three, Phree four, and Nyck five. If the
only steps with all four’s footprints are at the top and at the bottom, how
many steps have just one footprint?
211 Problem (A HSME 1992) For how many integers between 1 and 100
does
x2 + x − n
factor into the product of two linear factors with integer coefficients?
212 Problem (A HSME 1989) Five people are sitting at a round table. Let
f ≥ 0 be the number of people sitting next to at least one female and
m ≥ 0 be the number of people sitting next to at least one male. Find the
number of possible ordered pairs (f, m).
Answer: 8
213 Example Find the number of lattice points (x, y) that satisfy
|x| + |y| ≤ 3.
215 Example How many positive integers have 4 digits? None of the
integers is to have 0 as its leftmost digit.
217 Example How many different n-digit positive integers do not have the
digit 5?
218 Example Prove that a set with n elements has 2n different subsets
(including the empty set and the set itself).
26 Chapter 3
Solution: We motivate the idea of the proof for the case when n = 3.
Suppose S = {a, b, c} is a set with three elements. Which each subset of
the set we associate a dyadic (0-1) ternary sequence writing 0 if the
element is not in the set, and 1 if the element belongs to the set. So with
the set ∅ we associate the sequence 000
the set {a} we associate the sequence 100
the set {b} we associate the sequence 010
the set {c} we associate the sequence 001
the set {a, b} we associate the sequence 110
the set {a, c} we associate the sequence 101
the set {b, c} we associate the sequence 011
the set {a, b, c} we associate the sequence 111
In the general case, we may supposed the elements of the set to be
ordered as (x1 , x2 , . . . , xn ). To each subset T of the set, we associate a
dyadic sequence as above, writing 1 if xi ∈ T and 0 if xi 6∈ T . For each of
n positions we have two choices, and so the total elements of subsets is
· · 2} = 2n .
2| ·{z
n 2 0s
219 Example Out of nine different pairs of shoes, in how many ways could
I choose a right shoe and a left shoe, which do not form a pair?
Solution: The left shoe can be chosen in 9 ways, the right shoe can be
chosen in 8 ways, so as not to pair up with the first. The total number of
ways is thus 9 · 8 = 72.
Aliter: There are 9 · 9 = 81 ways of choosing a left shoe and a right shoe.
Of those, 9 pairs match, so the required number of ways is 81 − 9 = 72.
Sometimes we need to combine both the addition and the multiplication
principle.
220 Example There are five Golden retrievers, six Irish setters, and eight
Poodles at the pound. In how many ways can two dogs be chosen if they
are not the same kind?
Two Basic Counting Principles 27
Solution: Notice that the order in which the dogs are chosen is
unimportant. One Golden retriever and one Irish setter can be chosen in
5 · 6 = 30 ways. One Golden retriever and one Poodle can be chosen in
5 · 8 = 40 ways. One Irish setter and one Poodle can be chosen in
6 · 8 = 48 ways. The total number of ways of choosing a pair that are not
of the same breed is thus 30 + 40 + 48 = 118.
Solution: There are 9 · 10j−1 j-digit positive integers. The total number of
digits in numbers with at most r digits is the arithmetic-geometric sum
j
X 10r − 1
g(r) = j · 9 · 10j−1 = r10r − .
j=1
9
10r − 1
As 0 < < 10r , we get
9
(r − 1)10r < g(r) < r10r .
28 Chapter 3
Thus g(1983) < 1983 · 101983 < 104 101983 = 101987 and
g(1984) > 1983 · 101984 > 103 101984 = 101987 . Therefore f(1987) = 1984.
Ad Pleniorem Scientiam
224 Problem Prove that there are 9 · 10n−1 integers with n ≥ 1 digits.
225 Problem How many positive palindromes are there with n digits?
n−1 n−2
Answer: 9 · 10 2 if n is odd, and 9 · 10 2 if n is even.
3.3 Permutations
Each of the arrangements which can be made by taking some or all of a
number of things is called a permutation. Thus the permutations which
can be made by taking the numbers {1, 2, 3, 4} two at the time are twelve
in number, namely,
12, 13, 14, 23, 24, 34,
21, 31, 41, 32, 43.
Their number can be easily calculated without having to enumerate them.
For by the product rule we can choose the first number in 4 ways and the
second number in three ways (we have already selected one number,
leaving us with 3). This gives 4 · 3 = 12 ways.
227 Example How many distinct four-letter words can be made with the
letters of the set {t, i, c, k} if (i) the letters are not to be repeated?, (ii) if the
letters can be repeated?
Solution: (i) The first letter can be any one of any 4. After choosing the
first letter, we have 3 choices for the second letter, 2 for the third, and 1
for the fourth. The total number of such words is thus 4 · 3 · 2 · 1 = 24.
Permutations 29
(ii) The first letter can be chosen in 4 ways. Since we are allowed to
repeat letters, the second letter can be also any of 4, etc. The total
number of words thus formed is 44 .
228 Example How many distinct six-digit integers that are multiples of 5
can be formed from the list of digits {1, 2, 3, 4, 5, 6} (i) if we don’t allow
repetition, (ii) if we allow repetition?
Solution: The last digit must perforce be 5. There remain five digits to fill
the remaining 5 spots, and these can be filled in 5! = 120 different ways.
(ii) Again the last digit must be five. The other five spots can be filled with
any of the 6 digits, so we have 65 = 7776.
229 Example In how many ways can one decompose the set
{1, 2, 3, . . . , 100} into subsets A, B, C satisfying
Solution: The conditions of the problem stipulate that both the region
outside the circles and R3 in diagram below will be empty. We are thus left
with 6 regions to distribute 100 numbers.
C To each of the 100 numbers we
may thus assign one of 6 labels. TheR number of sets thus required is 6100 .
$1in]
4
R6 R7
R3
A R2 R1 B
R5
230 Example (A IME 1993) How many even integers between 4000 and
7000 have four different digits?
last digit, 8 for the penultimate and 7 for the antepenultimate. This gives
280 ways. The total number sought is therefore 224 + 224 + 280 = 728.
233 Problem In how many ways can three students and two professors sit
in a row? In how many ways can they sit in a row if the students and the
professors are to sit within themselves (that is, we have a row of just
students and just professors, or viceversa)? In how many ways can they
sit if only the professors are to sit together (that is, the two professor are
always next to one another)?
Answer: 12
235 Problem How many different license plates are there involving three
letters and four digits if the three letters must appear together either at the
beginning or at the end of the plate?
237 Problem Find the number of ways in which five different English
books, six French books, three German books, and seven Russian books
can be arranged together on a shelf so that all books of the same
language are together.
Answer: 3!4!5!6!7!
238 Problem How many ways are there to seat ten boys and ten girls
around a circular table?
Answer: 19!
239 Problem A child has blocks of six different colours. If the child selects
one block of each colour, in how many ways can these be arranged in a
line?
240 Problem How many ten-digit multiples of five are there if no digit is to
be repeated?
Answer: 8 · 8! + 9!
Answer: 4536
32 Chapter 3
3.4 Combinations
Each of the groups or selections which can be made by taking some or all
of a number of things is called a combination.
The combinations which can be made by taking the numbers {1, 2, 3, 4}
two at the time are six in number, namely,
(n − k)!
If we multiply the above fraction by , we can easily see that
(n − k)!
n n!
(3.4) =
k k!(n − k)!
We now give some examples of the use of combinations.
Solution: We can choose the seven people in 20 ways. Of the seven, the
7
chairman can be chosen in 7 ways. Thus there are 7 20
7
= 542640.
Aliter: Choose the chairman first. This can be done in 20 ways. Out of the
nineteen remaining people, we must now choose six. This can be done in
19
= 1·2·3·4·5·6 = 27132 ways. The total number of ways desired is
19·18·17·16·15·14
6
hence 20 19
6
= 542640.
Solution: Choose the seven people first. This can be done in 20 ways.
7
Out of the seven, the choose the chairman first in 7 ways and then the
secretary in 6 ways. The total number of ways is therefore
7 · 6 20
7
= 3255840.
Aliter: If one chooses the chairman first, then the secretary and finally, the
remaining five members of the committee, one obtains
20 · 19 185
= 3255840 as before.
Now let a1 < a2 < · · · < an . It is easy to see that nk counts the numjber
of k-strings ai1 ai2 · · · aik which are increasing, since any such string
consists of different elements. Analogously, nk counts the number of
strings of b1 > b2 > · · · > bn which are decreasing.
there are 93 = 84 three-digit numbers with all the digits increasing. The
246 Example There are twenty students in a class. In how many ways
can the twenty students take five different tests if the four of the students
are to take each test?
Solution: We can choose the four students who are going to take thefirst
test in 20
4
. From the remaining ones, we can choose students in 16 4
to
take the second test. The third test can be taken in 4 ways, the fourth
12
20 16 12 8 4 20!
= 4 = 7332965640000.
4 4 4 4 4 4!
247 Example In how many ways can a woman choose three or more
lovers from seven eligible suitors?
Solution: She might choose three in 73 ways, four in 74 ways, etc.. The
248 Example How many times is the digit 3 listed in the numbers 1 to
1000?
Solution: We count those numbers that have exactly one 3, exactly two 3s
and exactly three 3s. There is only one numberin the range 1—1000 that
has 3 three times, namely 333. Suppose xyz, where x, y, z are digits, is to
have
the digit 3 exactly twice. We can choose these two positions in
3
2
= 3 ways. The third position can be filled with any of the remaining
nine digits. Thus there are 9 · 3 = 27 numbers in the range 1—1000 that
contain the digit 3 exactly twice. Similarly, there are 92 31 = 243 numbers
that use the digit 3 exactly once. This means that the digit 3 appears
3 · 1 + 2 · 27 + 1 · 243 = 300 times.
Combinations 35
Solution: Align the six students first. There are five spaces between
them. A professor will be between two students if and only if he occupies
one of these five spaces. Thus we must choose three spaces out of five,
which can be done in 53 = 10 different ways. Since the order of the
professors can be permuted, the final answer is 10 × 3! = 60.
250 Example In how many ways can a deck of playing cards can be
arranged if no two hearts are adjacent?
Solution: We align the 39 cards which are not hearts first. There are
thirty-eight spaces between them, and one extra space before the first
card and another extra space after the last card, giving a total
of 40
spaces where the hearts can be placed. There are thus 13 ways of
40
choosing the places where the hearts can go. Since we are interested in
arrangements, we can arrange the hearts in 13! ways and the none
hearts in 39! ways. The total number of arrangements is thus 40
13
13!39!.
Ad Pleniorem Scientiam
252 Problem (A HSME 1989) Mr. and Mrs. Zeta want to name baby Zeta
so that its monogram (first, middle, and last initials) will be in alphabetical
order with no letters repeated. How many such monograms are possible?
36 Chapter 3
253 Problem In how many ways can you pack twelve books into four
parcels if one parcel has one book, another parcel has five books, and
another has two books, and another has four books?
Answer: 12 11
6 4
1 5 2 4
254 Problem In how many ways can a person invite three of his six
friends to lunch every day for twenty days if he has the option of inviting
the same or different friends from previous days?
6 20
Answer:
3
Answer: 9
5
3 3
256 Problem In how many ways can the following prizes be given away to
a class of twenty students: first and second Latin, first and second
Mathematics, first Science, and first French?
Answer: 57760000
257 Problem How many integers less than 10000 can be made with the
eight digits 0, 1, 2, 3, 4, 5, 6, 7?
Answer: 4095
258 Problem In how many ways can seven persons form a ring? In how
many ways can seven Englishmen and seven Americans sit down at a
round table, no two Americans being together?
259 Problem From three guavas, four peaches, and two oranges, how
many selections of fruit can be made, taking at least one of each kind?
Distributions 37
Answer:
3 3 3 4 4 4 4 2 2
+ + + + + + = 315
1 2 3 1 2 3 4 1 2
260 Problem (A IME 1984) A gardener plants three maple trees, four oak
trees and five birch trees in a row. He plants them in random order, each
arrangement being equally likely. Let m/n in lowest terms be the
probability that no two birch trees are next to each other. Find m + n.
Answer: 106.
3.5 Distributions
261 Theorem Let n be a positive integer. The number of positive solutions
to
x1 + x 2 + · · · + x r = n
is
n−1
.
r−1
262 Example In how many ways can 100 be written as the sum of four
(positive) summands?
Ad Pleniorem Scientiam
264 Problem There are thirty students in a class. In how many ways can
the class elect a President and a Vice-President if no student can be
elected for both offices?
38 Chapter 3
Answer: 870
for 0 ≤ k ≤ r ≤ n.
270 Example (A IME 1989) Ten points are marked on a circle. How many
distinct convex polygons of three or more sides can be drawn using some
(or all) of the ten points as vertices? (Polygons are distinct unless they
have exactly the same vertices.)
Combinatorial Identities 39
Solution: (i) Since the points are not collinear and any two points
determine a straight line, there are 2 lines in total.
n
(iv) Once a point is chosen, there remain to choose two points from the
remaining n − 1 points. We can do this in 2 ways.
n−1
40 Chapter 3
Ad Pleniorem Scientiam
Answer: 17 12
7 3 17
14
5 5 4 3
; 3 4
210
4 4 4 4 4
0 1 2 3 4
5 5 5 5 5 5
0 1 2 3 4 5
6 6 6 6 6 6 6
0 1 2 3 4 5 6
......................................
When the numerical values are substituted, the triangle then looks like
this.
1
121
1331
14641
1 5 10 10 5 1
1 6 15 20 15 6 1
.....................................
We see from Pascal’s Triangle that binomial coefficients are
symmetric.
This symmetry is easily justified by the identity k = n−k . We also
n n
notice that the binomial coefficients tend to increase until they reach the
middle, and that they decrease symmetrically. That is, the n
k
satisfy
n n n n n n n
0
< 1 < · · · < [n/2]−1 < [n/2] > [n/2]+1 > [n/2]+2 > · · · > n−1 >
n
if n is even, and that 0 < 1 < · · · < [n/2]−1 < [n/2] = [n/2]+1 >
n n n n n
n
n n n
> nn for odd n. We call this property the
[n/2]+2
> [n/2]+3 > · · · > n−1
unimodality of the binomial coefficients. Forexample, without finding the
exact numerical values we can see that 17 < 69 and that
200 200
200
= 200 < 200 .
131 69 99
We now present some examples on the use of binomial coefficients.
Solution: We have
n i n!i! n!(n − j)!
= =
i j i!(n − i)!j!(i − j)! (n − j)!j!(n − i)!(i − j)!
which is the same as
n n−j
.
j i−j
Solution: We have
n−1 n−1 (n − 1)! (n − 1)!
+ = +
k−1 k (k − 1)!(n − k)! k!(n − k − 1)!
(n − 1)! 1 1
= +
(n − k − 1)!(k − 1)! n − k k
(n − 1)! n
=
(n − k − 1)!(k − 1)! (n − k)k
n!
=
(n −
k)!k!
n
=
k
Solution:
Assume that
n n n n
. This yields
a = r , a + d = r+1 , a + 2d = r+2 , a + 3d = r+3
n n n
2 = + ,
r+1 r r+2
or equivalently
r+1 n−r−1
2= + (∗).
n−r r+2
This is a quadratic equation in r, having r as one of its roots. The
condition that the binomial coefficients are in arithmetic progression
means that r + 1 is also a root of (∗). Replacing r by n − r − 2 we also
obtain
n−r−1 r+1
2= + ,
r+2 n−r
which is the same as (∗). This means that n − r − 3 and n − r − 2 are also
roots of (∗). Since a quadratic equation can only have two roots, we must
have r = n − r − 3. The four binomial coefficients must then be
2r + 3 2r + 3 2r + 3 2r + 3
, , , .
r r+1 r+2 r+3
But these cannot be in an arithmetic progression, since binomial
coefficients are unimodal and symmetric.
278 Example Let N(a) denote the number of solutions to the equation
a = nk for nonnegative integers n, k. For example,
Solution: Let b be the first time that 2b > a. By the unimodality of the
b
binomial coefficients, i = j is monotonically increasing in i and j.
i+j i+j
Hence
b+i+b+j b+b+j 2b
≥ ≥ >a
b+j b b
44 Chapter 3
for all i, j ≥ 0. Hence i+j = a implies i < b, or j < b. Also, for each fixed
j
value of i (or j), i = a has at most one solution. It follows that
i+j
(a + b)n .
(1 + x)(1 + x) · · · (1 + x)
| {z }
n times
follows that
n
n n X n k
n n n n 2
(1 + x) = + x+ x + ··· + x = x .
0 1 2 n k=0
k
n
X
n j n n−i
= 2 , i ≤ n.
j=i
j i i
n j n n−i
= .
j i i j−i
Thus
n
X Xn
n j n n−i
= .
j=0
j i i j=0 j − i
n
X n−i
X
n−i n−i
= = 2n−i ,
j=0
j−i j=0
j
X m + k
n+m+1
= .
k≤n
k n
46 Chapter 3
X mn−1 n + 1 n n+1
= / = .
0≤k≤m
k k m m n + 1 − m
and
50
X
100
= 299 .
k=0
2k
The desired sum is the difference of these two values 2100 − 299 = 299 .
48 Chapter 3
P
Solution: By the Binomial Theorem, the complete sum 11 2 = 311 .
11 k
k=0 k
The required sum lacks the zeroth term, 11 20 = 1, and the eleventh
0
term, 11 211 from this complete sum. The required sum is thus
11
311 − 211 − 1.
ak 2(10 − k + 1)
= .
ak−1 k
This will be < 1 if k < 22/3 < 8. Thus a0 < a1 < a2 < . . . < a7 . If
k > 22/3, the ratio above will be < 1. Thus a7 > a8 > a9 > a10 . The
largest term is that of k = 7, i.e. the eighth term.
and
10 4 6 10
(2x) (9) ≥ (2x)5 (9)5 .
4 5
After simplifying the factorials, the two inequalities sought are
x ≥ 18/7
and
15/4 ≥ x.
The only integral x that satisfies this is x = 3.
Xn
0 n−1 n k−1
f (x) = n(1 + x) = k x .
k=0
k
Letting x = 1 we obtain
Xn
n−1 n
n2 = k ,
k=0
k
n
X n−1
X
n−1 n−1
= = 2n−1 ,
k=0
k−1 k=0
k
Xn
0 n−1 n k−1
f (x) = n(1 + x) = k x
k=0
k
and
Xn
0 n−1 n k
xf (x) = nx(1 + x) = k x .
k=0
k
Differentiating this last expression,
which equals
n
X
2n k−1
k x .
k=0
k
Letting x = 1 in the above expression,
n
X
n−1 n−1 n
2
n2 + n(n − 1)2 = k ,
k=0
k
Solution: We have
Z1 Z1 X
n
n n
(1 + x) dx = xk dx.
0 0 k=0
k
The Binomial Theorem 51
from where we obtain the dextral side of the identity we want to prove. On
the other hand, evaluating the integral directly by expanding using the
Binomial Theorem,
Z1 Z1 Xn
1 − (1 − x)n n
dx = (−1)k−1 xk−1 dx,
0 x 0 k=1 k
Solution: Let X
S= k(k + 1).
k≤n
Then
X k(k + 1) X k + 1
S/2! = = .
k≤n
2! k≤n
2
By the preceding problem
X k + 1
n+2
= .
k≤n
2 3
297 Problem The expansion of (x + 2y)20 contains two terms with the
same coefficient, Kxa yb and Kxa+1 yb−1 . Find a.
holds true.
Answer: 11.
306 Problem If
1991 1991 1991 1991
+ + + ··· + = 2a ,
1 3 5 1991
find a.
Answer: a = 1990.
Answer: True.
Answer: True.
Answer: 20
8
(28 )(312 ).
(x3/2 + y)15 ?
Answer: 15
8
.
Answer: 840.
312 Problem Shew that the binomial coefficients satisfy the following
hexagonal property:
n−1 n n+1 n−1 n+1 n
= .
k−1 k+1 k k k+1 k−1
Answer: 166-th
314 Problem (P UTNAM 1971) Shew that for 0 < < 1 the expression
(A) 49
+ 50 + · · · + 99
49 49 49
(B) 100
50
50 2
2 2
(C) + 50 + · · · + 50
0 1 50
(D) 200
100
Answer: D.
Answer: 1000
6
Answer: 0, as 15 15
, 15 15
, etc.
1
= 14 2
= 13
Answer: 0.
323 Problem (A IME 1992) In which row of Pascal’s triangle (we start with
zeroth row, first row ,etc.) do three consecutive entries occur that are in
the ratio 3 : 4 : 5?
Answer: 62-nd
(x + 2y + z)8
326 Example How many different terms are there in the expansion of
(x + y + z + w + s + t)20 ?
n1 + n2 + · · · + n6 = 20.
Ad Pleniorem Scientiam
Answer: 12
2
.
Multinomial Theorem 59
(1 + 3x + 2x3 )10 ?
Answer: 6 10 10
1,1,8
+ 34 0,4,6
.
(x + y + z)10 ?
Answer: 10
2,3,5
.
60 Chapter 3
Chapter 4
Arithmetic
If a does not divide b we write a 6 |b. It should be clear that if a|b and
b 6= 0 then 1 ≤ |a| ≤ |b|.
am + nb = c(sm + tn),
61
62 Chapter 4
333 Example Show that the square of any integer is of the form 4k or of
the form 4k + 1. That is, the square of any integer is either divisible by 4
or leaves remainder 1 upon division by 4.
11 . . . 1} = 11
| {z . . 11} 00 + 12 − 1 = 100 · 11
| .{z . . 11} +12 − 1.
| .{z
n 1 0s n−2 1 0 s n−2 1 0 s
336 Example Show that the square of any prime greater than 3 leaves
remainder 1 upon division by 12.
Therefore
(3k ± 1)2 − 1
n+1= + 1 = 3k2 ± 2k + 1 = k2 + k2 + (k ± 1)2 ,
3
as we wanted to show.
340 Example Show that from any three integers, one can always choose
two so that a3 b − ab3 is divisible by 10.
Ad Pleniorem Scientiam
n + 1|n2 + 1.
343 Problem Show that the square of any integer is of the form 3k or
3k + 1.
Division Algorithm 65
345 Problem Show that if the sides of a right triangle are all integers, then
3 divides one of the lengths of a side.
346 Problem Given that 5 divides (n + 2), which of the following are
divisible by 5
n2 − 4, n2 + 8n + 7, n4 − 1, n2 − 2n?
be divisible by n2 + 2.
Answer: 13
350 Problem Show that the product of two integers of the form 4n + 1 is
again of this form. Use this fact and an argument by contradiction similar
to Euclid’s to prove that there are infinitely many primes of the form 4n − 1.
351 Problem Prove that there are infinitely many primes of the form
6n − 1.
352 Problem Prove that there are infinitely many primes p such that p − 2
is not prime.
354 Problem Let n > 1 be a positive integer. Prove that if one of the
numbers 2n − 1, 2n + 1 is prime, then the other is composite.
355 Problem Prove that there are infinitely many integers n such that
4n2 + 1 is divisible by both 13 and 5.
356 Problem Prove that any integer n > 11 is the sum of two positive
composite numbers.
x 6 |y and (x + 1) 6 |y,
and also
x 6 |(y + 1) and (x + 1) 6 |(y + 1).
361 Example Find all the integers with initial digit 6 such that if this initial
integer is suppressed, the resulting number is 1/25 of the original number.
362 Example (I MO 1968) Find all natural numbers x such that the product
of their digits (in decimal notation) equals x2 − 10x − 22.
x = a0 + a1 10 + a2 102 + · · · + an 10n , ak ≤ 9, an 6= 0.
Let P(x) be the product of the digits of x, P(x) = x2 − 10x − 22. Now
P(x) = a0 a1 · · · an ≤ 9n an < 10n an ≤ x (strict inequality occurs when x
68 Chapter 4
has more than one digit). This means that x2 − 10x − 22 ≤ x which entails
that x < 13, whence x has one digit or x = 10, 11 or 12. Since
x2 − 10x − 22 = x has no integral solutions, x cannot have one digit. If
x = 10, P(x) = 0, but x2 − 10x − 22 6= 0. If x = 11, P(x) = 1, but
x2 − 10x − 22 6= 1. The only solution is seen to be x = 12.
We must show that this last quantity is an integer, that is, that 3 divides
2 · 10n + 1 = 2 00 . . 00} 1. But the sum of the digits of this last quantity is 3,
| .{z
n−1 0 0 s
2 · 10n + 1
which makes it divisible by 3. In fact, = 6| .{z
. . 6} 7
3
n−1 6 s
0
The Decimal Scale 69
366 Example (A IME 1992) For how many pairs of consecutive integers in
{1000, 1001, . . . , 2000}
is no carrying required when the two integers are added?
Solution: Other than 2000, a number on this list has the form
n = 1000 + 100a + 10b + c, where a, b, c are digits. If there is no carrying
in n + n + 1 then n has the form
1999, 1000 + 100a + 10b + 9, 1000 + 100a + 99, 1000 + 100a + 10b + c
with 0 ≤ a, b, c ≤ 4, i.e., five possible digits. There are 53 = 125 integers
of the form 1000 + 100a + 10b + c, 0 ≤ a, b, c ≤ 4, 52 = 25 integers of the
form 1000 + 100a + 10b + 9, 0 ≤ a, b ≤ 4, and 5 integers of the form
1000 + 100a + 99, 0 ≤ a ≤ 4. The total of integers sought is thus
125 + 25 + 5 + 1 = 156.
367 Example (A IME 1994) Given a positive integer n, let p(n) be the
product of the non-zero digits of n. (If n has only one digit, then p(n) is
equal to that digit.) Let
S = p(1) + p(2) + · · · + p(999).
Find S.
70 Chapter 4
368 Example (A IME 1992) Let S be the set of all rational numbers r,
0 < r < 1, that have a repeating decimal expansion of the form
0.abcabcabc . . . = 0.abc,
where the digits a, b, c are not necessarily distinct. To write the elements
of S as fractions in lowest terms, how many different numerators are
required?
abc
Solution: Observe that 0.abcabcabc . . . = , and that 999 = 33 · 37. If
999
abc is neither divisible by 3 nor by 37, the fraction is already in lowest
terms. By Inclusion-Exclusion there are
999 999 999
999 − + + = 648
3 37 3 · 37
s
such fractions. Also, fractions of the form where s is divisible by 3 but
37
not by 37 are in S. There are 12 fractions of this kind (with s = 3, 6, 9, 12,
l
. . . , 36). We do not consider fractions of the form t , t ≤ 3 with l divisible
3
by 37 but not by 3, because these fractions are > 1 and hence not in S.
The total number of distinct numerators in the set of reduced fractions is
thus 640 + 12 = 660.
The Decimal Scale 71
Problems
369 Problem Find an equivalent fraction for the repeating decimal 0.3172.
370 Problem A two-digit number is divided by the sum of its digits. What
is the largest possible remainder?
11
| .{z
. . 11}
221 1 0 s
is a composite number.
a = 111
| {z. . . 1}
m 1 0s
b = 1 000
| {z. . . 0} 5.
m−1 0 0 s
. . 3} · 6| .{z
3| .{z . . 6} ?
666 3 0 s 666 6 0 s
374 Problem Show that there exist no integers with the following property:
if the initial digit is suppressed, the resulting integer is 1/35 of the original
number.
375 Problem Show that the sum of all the integers of n digits, n ≥ 3, is
494 99 . . . 9} 55 00
| {z . . . 0} .
| {z
n−3 9 0 s n−2 0 0 s
72 Chapter 4
11 . . . 1} − 22
| {z . . . 2}
| {z
2n 1 0 s n 2 0s
is a perfect square.
377 Problem A whole number is equal to the arithmetic mean of all the
numbers obtained from the given number with the aid of all possible
permutation of its digits. Find all whole numbers with that property.
378 Problem The integer n is the smallest multiple of 15 such that every
n
digit of n is either 0 or 8. Compute .
15
0.12345678910111213141516171819202122 . . .
, which is the sequence of natural numbers written after the decimal point,
is irrational.
381 Problem Let t be a positive real number. Prove that there is a positive
integer n such that the decimal expansion of nt contains a 7.
383 Problem (A IME 1988) Find the smallest positive integer whose cube
ends in 888.
Non-decimal Scales 73
384 Problem (A IME 1986) In the parlor game, the “magician” asks one of
the participants to think of a three-digit number abc, where a, b, c
represent the digits of the number in the order indicated. The magician
asks his victim to form the numbers
to add these numbers and to reveal their sum N. If told the value of N,
the magician can identify abc. Play the magician and determine abc if
N = 319.
385 Problem (A IME 1988) For any positive integer k, let f1 (k) denote the
square of the sums of the digits of k. For n ≥ 2, let fn (k) = f1 (fn−1 (k)).
Find f1988 (11).
387 Problem (I MO 1962) Find the smallest natural number having the last
digit 6 and if this 6 is erased and put in from of the other digits, the
resulting number is four times as large as the original number.
n = a0 + a1 r + a2 r2 + · · · + ak rk , 0 ≤ at ≤ r − 1, ak 6= 0, rk ≤ n < rk+1 .
5213 = a4 74 + a3 73 + a2 72 + a1 7 + a0 .
13
390 Example Express the fraction in base-six.
16
Solution: Write
13 a1 a2 a3 a4
= + 2 + 3 + 4 + ···
16 6 6 6 6
Non-decimal Scales 75
391 Example Prove that 4.41r is a perfect square in any scale of notation.
Solution: 2
4 4 1
4.41r = 4 + + 2 = 2+
r r r
In the binary scale these numbers are, of course, the ascending natural
numbers 1, 2, 3, 4, . . .. Therefore to obtain the 100th term of the sequence
we write 100 in binary and then translate this into ternary: 100 = 11001002
and 11001003 = 36 + 35 + 32 = 981.
The algorithm given moves the binary point one unit to the right. For x0 to
equal x5 we need (0.a1 a2 a3 a4 a5 a6 a7 . . .)2 = (0.a6 a7 a8 a9 a10 a11 a12 . . .)2 .
This will happen if and only if x0 has a repeating expansion with
a1 a2 a3 a4 a5 as the repeating block. There are 25 = 32 such blocks. But if
a1 = a2 = · · · = a5 = 1 then x0 = 1, which lies outside ]0, 1[. The total
number of values for which x0 = x5 is therefore 32 − 1 = 31.
Problems
394 Problem Express the decimal number 12345 in every scale from
binary to base-nine.
396 Problem Let C denote the class of positive integers which, when
written in base-three, do not require the digit 2. Prove that no three
integers in C are in arithmetic progression.
398 Problem Let bxc denote the greatest integer less than or equal to x.
Does the equation
have a solution?
399 Example Prove that there is no integer in the open interval ]0, 1[.
√
400 Example Prove that 2 is irrational.
√
Solution:√The proof is by contradiction. Suppose that 2 were rational,
i.e., that 2 = ab for some integers a, b, b 6= 0. This implies that the set
√ √
A = {n 2 : both n and n 2 positive integers}
401 Example Let a, b, c be integers such that a6 + 2b6 = 4c6 . Show that
a = b = c = 0.
a2 + b 2
402 Example (I MO 1988) If a, b are positive integers such that is
1 + ab
a2 + b 2
an integer, then show that must be a square.
1 + ab
Well-Ordering Principle 79
a2 + b 2
Solution: Suppose that = k is a counterexample of an integer
1 + ab
which is not a perfect square, with max(a, b) as small as possible. We
may assume without loss of generality that a < b for if a = b then
2a2 2
0<k= = 2 − < 2,
a2 + 1 a2 + 1
which forces k = 1, a square.
Now, a2 + b2 − k(ab + 1) = 0 is a quadratic in b with sum of roots ka and
product of roots a2 − k. Let b1 , b be its roots, so b1 + b = ka, bb1 = a2 − k.
As a, k are positive integers, supposing b1 < 0 is incompatible with
a2 + b21 = k(ab1 + 1). As k is not a perfect square, supposing b1 = 0 is
incompatible with a2 + 02 = k(0 · a + 1). Also
a2 − k b2 − k k
b1 = < = b − < b.
b b b
a2 + b21
Thus we have shown b1 to be a positive integer with = k smaller
1 + ab1
than b. This is a contradiction to the choice of b. Such a counterexample
a2 + b 2
k cannot exist, and so must be a perfect square. In fact, it can be
1 + ab
a2 + b 2
shown that is the square of the greatest common divisor of a and
1 + ab
b.
Problems
404 Problem Prove that the equality x2 + y2 + z2 = 2xyz can hold for
whole numbers x, y, z only when x = y = z = 0.
405 Problem Show that the series of integral squares does not contain an
infinite arithmetic progression.
This entails
33n − 26n − 1 = 169M.
Now
33n+3 − 26n − 27 = 27 · 33n − 26n − 27
= 27(33n − 26n − 1) + 676n
= 27(169M) + 169 · 4n
= 169(27M + 4n),
and so the truth of P(n − 1) implies the truth of P(n). The assertion then
follows for all n ≥ 1 by PMI.
Mathematical Induction 81
for some positive integer b.” We see that P(1) is true since
√ √
(1 + 2)2 + (1 − 2)2 = 6,
and √ 2 √ √
(1 + 2) − (1 − 2)2 = 4 2.
Assume now that P(n − 1), i.e., assume that
√ 2(n−1) √
(1 + 2) + (1 − 2)2(n−1) = 2N
410 Example Let s be a positive integer. Prove that every interval [s, 2s]
contains a power of 2.
1 1 1 1 1 1 1 1
+ + ··· + + = + + = 1.
2a1 2a2 2ak 4 4 2 4 4
1 1 1 1 1 1 1 1
+ + ··· + + = + + = 1.
2a1 2a2 2ak 3 6 2 3 6
Therefore
Problems
1 1 1
+ + ··· + > 1.
n+1 n+2 3n + 1
419 Problem Prove that for all positive integers n and all real numbers x,
for n ∈ N.
4n (2n)!
< .
n+1 (n!)2
1
424 Problem Let k be a positive integer Prove that if x + is an integer
x
1
then x + k is also an integer.
k
x
4.6 Congruences
429 Definition The notation a ≡ b mod n is due to Gauß, and it means
that n|(a − b).
ax + bu ≡ ay + bv mod n.
xu ≡ yv mod n.
is divided by 4.
436 Example Prove that 7 divides 32n+1 + 2n+2 for all natural numbers n.
32n+1 ≡ 3 · 9n ≡ 3 · 2n mod 7
and
2n+2 ≡ 4 · 2n mod 7
. Hence
32n+1 + 2n+2 ≡ 7 · 2n ≡ 0 mod 7,
for all natural numbers n.
yield
−24 · 228 ≡ mod 641,
which means that 641|(232 + 1).
22225555 +55552222 ≡ 35555 +42222 ≡ (35 )1111 +(42 )1111 ≡ 51111 −51111 ≡ 0 mod 7.
7
Solution: We must find 77 mod 10. Now, 72 ≡ −1 mod 10, and so
73 ≡ 72 · 7 ≡ −7 ≡ 3 mod 10 and 74 ≡ (72 )2 ≡ 1 mod 10. Also, 72 ≡ 1
mod 4 and so 77 ≡ (72 )3 · 7 ≡ 3 mod 4, which means that there is an
integer t such that 77 = 3 + 4t. Upon assembling all this,
7
77 ≡ 74t+3 ≡ (74 )t · 73 ≡ 1t · 3 ≡ 3 mod 10.
consists of those positive multiples of 3 that are one less than a perfect
square. What is the remainder when the 1994-th term of the sequence is
divided by 1000?
Ad Pleniorem Scientiam
443 Problem Prove that 0, 1, 3, 4, 9, 10, and 12 are the only perfect squares
mod 13.
452 Problem (A HSME 1992) What is the size of the largest subset S of
{1, 2, . . . , 50} such that no pair of distinct elements of S has a sum divisible
by 7?
453 Problem Prove that there are no integer solutions to the equation
x2 − 7y = 3.
456 Problem Prove that the sum of the decimal digits of a perfect square
cannot be equal to 1991.
459 Problem (U SAMO 1986) What is the smallest integer n > 1, for which
the root-mean-square of the first n positive integers is an integer?
consists of all those multiples of 3 which are one less than a square. Find
the remainder when the 1994th term is divided by 1000.
Answer: 63
464 Problem (A IME 1983) Let an = 6n + 8n . Find the remainder when a83
is divided by 49.
465 Problem Show that if 9|(a3 + b3 + c3 ), then 3|abc, for the integers
a, b, c.
94 Chapter 4
470 Example Prove that n5 − 5n3 + 4n is always divisible by 120 for all
integers n.
Solution: We have
A = a10 a9 a8 . . . a1
and
A 0 = b10 b9 b8 . . . b1 ,
96 Chapter 4
a1 + a2 + · · · + a10 = b1 + b2 + · · · + b10 ,
we have
a1 +b1 +a2 +b2 +· · ·+ai +bi +ai+1 +bi+1 +· · ·+a10 +b10 = 2(a1 +a2 +· · ·+a10 ),
472 Example (P UTNAM 1956) Prove that every positive integer has a
multiple whose decimal representation involves all 10 digits.
m + 1, m + 2, . . . , m + n
473 Example (P UTNAM 1966) Let 0 < a1 < a2 < . . . < amn+1 be mn + 1
integers. Prove that you can find either m + 1 of them no one of which
divides any other, or n + 1 of them, each dividing the following.
476 Example The sum of some positive integers is 1996. What is their
maximum product?
478 Example For how many integers n in {1, 2, 3, . . . , 100} is the tens digit
of n2 odd?
Solution: In the subset {1, 2, . . . 10} there are only two values of n (4 and
6) for which the digits of the tens of n2 is odd. Now, the tens digit of
(n + 10)2 = n2 + 20n + 100 has the same parity as the tens digit of n2 .
Thus there are only 20 n for which the prescribed condition is verified.
Problems
5 + 55 + 555 + · · · + 5| .{z
. . 5} .
n 5 0s
Miscellaneous Problems with Integers 99
√
480 Problem Show that for all numbers a 6= 0, a 6= ±i 3 the following
formula of Reyley (1825) holds.
3 3 3
a6 + 45a5 − 81a2 + 27 −a2 + 30a2 − 9 −6a3 + 18a
a= + + .
6a(a2 + 3)2 6a(a2 + 3) (a2 + 3)2
is divisible by 8640.
bx2 − x − 2c = bxc.
489 Problem Find, with proof, the unique square which is the product of
four consecutive odd numbers.
490 Problem (P UTNAM 1989) How many primes amongst the positive
integers, written as usual in base-ten are such that their digits are
alternating 1’s and 0’s, beginning and ending in 1?
491 Problem Let a, b, c be the lengths of the sides of a triangle. Show that
495 Problem Demonstrate that there are infinitely many square triangular
numbers.
498 Problem Are there five consecutive positive integers such that the
sum of the first four, each raised to the fourth power, equals the fifth
raised to the fourth power?
a1 + a 2 + a 3 + · · · + a n
if we were able to find {vk } satisfying ak = vk − vk−1 . For
a1 +a2 +a3 +· · ·+an = v1 −v0 +v2 −v1 +· · ·+vn−1 −vn−2 +vn −vn−1 = vn −v0 .
3 4 5 100
· · ··· ,
2 3 4 99
103
104 Chapter 5
whence
100
P = 22 − 1.
Solution: Multiplying both sides by sin π7 and using sin 2x = 2 sin x cos x
we obtain
π π π 2π 4π
sin P = (sin cos ) · cos · cos
7 7 7 7 7
1 2π 2π 4π
= (sin cos ) · cos
2 7 7 7
1 4π 4π
= (sin cos )
4 7 7
1 8π
= sin .
8 7
As sin 7 = − sin 7 , we deduce that
π 8π
1
P=− .
8
Telescopic cancellation 105
Solution: Let
1 3 5 9999
A= · · ···
2 4 6 10000
and
2 4 6 10000
B= · · ··· .
3 5 7 10001
Clearly, x2 − 1 < x2 for all real numbers x. This implies that
x−1 x
<
x x+1
whenever these four quantities are positive. Hence
n! = 1 · 2 · 3 · · · n.
Answer: 2400.
Answer: 9.
2n +1
22 − 2.
Arithmetic Sums 107
n(n + 1)
1 + 2 + ··· + n = .
2
To obtain a closed form, we utilise Gauss’ trick:
If
An = 1 + 2 + 3 + · · · + n
then
An = n + (n − 1) + · · · + 1.
Adding these two quantities,
An = 1 + 2 + ··· + n
An = n + (n − 1) + · · · + 1
2An = (n + 1) + (n + 1) + · · · + (n + 1)
= n(n + 1),
n(n + 1)
since there are n summands. This gives An = .
2
We summarise this as
n(n + 1)
(5.1) 1 + 2 + ··· + n = .
2
For example,
100(101)
1 + 2 + 3 + · · · + 100 = = 5050.
2
Applying Gauss’s trick to the general arithmetic sum
(a) + (a + d) + (a + 2d) + · · · + (a + (n − 1)d)
we obtain
(5.2)
n(2a + (n − 1)d)
(a) + (a + d) + (a + 2d) + · · · + (a + (n − 1)d) =
2
108 Chapter 5
511 Example Find the sum of all the integers from 1 to 1000 inclusive,
which are not multiples of 3 or 5.
Solution: One computes the sum of all integers from 1 to 1000 and weeds
out the sum of the multiples of 3 and the sum of the multiples of 5, but
puts back the multiples of 15, which one has counted twice. The desired
sum is
(1 + 2 + 3 + · · · + 1000) − (3 + 6 + 9 + · · · + 999)
−(5 + 10 + 15 + · · · + 1000)
+(15 + 30 + 45 + · · · + 990)
= (1 + 2 + 3 + · · · + 1000) − 3(1 + 2 + 3 + · · · + 333)
−5(1 + 2 + 3 + · · · + 200)
+15(1 + 2 + 3 + · · · + 66)
= 500500 − 3 · 55611 − 5 · 20100 +
= 266332
512 Example Each element of the set {10, 11, 12, . . . , 19, 20} is multiplied
by each element of the set {21, 22, 23, . . . , 29, 30}. If all these products are
added, what is the resulting sum?
(20 + 10)(11)
10 + 11 + · · · + 20 = = 165
2
and
(30 + 21)(10)
21 + 22 + · · · + 30 = = 255.
2
The required total is (165)(255) = 42075.
n = 1, l = 999,
n = 5, l = 197,
n = 16, l = 54,
n = 25, l = 27.
514 Example Find the sum of all integers between 1 and 100 that leave
remainder 2 upon division by 6.
Ad Pleniorem Scientiam
2 n2 (n2 + 1)
2
1 + 2 + 3 + · · · + (n − 1) + n = .
2
1 + 3 + 5 + · · · + 2n − 1 = n2 .
1 2
20 + 20 + 20 + · · · + 40.
5 5
Answer: 3030
110 Chapter 5
T2 T3 T4 Tn
Pn = · · ··· .
T2 − 1 T3 − 1 T4 − 1 Tn − 1
Find P1991 .
Answer: 5973
1993
b2 , a2 , c2
1=1
2+3+4=1+8
5 + 6 + 7 + 8 + 9 = 8 + 27
10 + 11 + 12 + 13 + 14 + 15 + 16 = 27 + 64
Conjecture the law of formation and prove your answer.
(1)
Geometric Sums 111
(3, 5)
(7, 9, 11)
(13, 15, 17, 19)
(21, 23, 25, 27, 29)
...............................
Find the sum of the nth row.
524 Problem The first term of an arithmetic progression is 14 and its 100th
term is −16. Find (i) its 30th term and (ii) the sum of all the terms from the
first to the 100th.
1 + 2 + 4 + · · · + 1024.
Solution: Let
S = 1 + 2 + 4 + · · · + 1024.
Then
2S = 2 + 4 + 8 + · · · + 1024 + 2048.
Hence
Solution: We have
1 1 1 1 1
x = 2 + 3 + · · · + 99 + 100 .
3 3 3 3 3
Then
2
3
x = x − 13 x
= ( 13 + 312 + 313 + · · · + 3199 )
−( 312 + 313 + · · · + 3199 + 1
3100
)
1
= 13 − 3100 .
From which we gather
1 1
x=
− .
2 2 · 399
The following example presents an arithmetic-geometric sum.
a = 1 + 2 · 4 + 3 · 42 + · · · + 10 · 49 .
Solution: We have
4a = 4 + 2 · 42 + 3 · 43 + · · · + 9 · 49 + 10 · 410 .
Now, 4a − a yields
3a = −1 − 4 − 42 − 43 − · · · − 49 + 10 · 410 .
Solution: We have
1
Sn − Sn = (1+1/2+1/4+· · ·+1/2n )−(1/2+1/4+· · ·+1/2n +1/2n+1 ) = 1−1/2n .
2
Whence
Sn = 2 − 1/2n .
So as n varies, we have:
S1 = 2 − 1/20 = 1
S2 = 2 − 1/2 = 1.5
S3 = 2 − 1/22 = 1.875
S4 = 2 − 1/23 = 1.875
S5 = 2 − 1/24 = 1.9375
S6 = 2 − 1/25 = 1.96875
S10 = 2 − 1/29 = 1.998046875
S = a + ar + ar2 + · · · + arn−1 .
rS = ar + ar2 + · · · + arn .
Hence
529 Example A fly starts at the origin and goes 1 unit up, 1/2 unit right,
1/4 unit down, 1/8 unit left, 1/16 unit up, etc., ad infinitum. In what
coordinates does it end up?
530 Problem The 6th term of a geometric progression is 20 and the 10th
is 320. Find (i) its 15th term, (ii) the sum of its first 30 terms.
n2 − 02 = 2(1 + 2 + 3 + · · · + n) − n.
n(n + 1)
1 + 2 + 3 + · · · + n = ·n2 /2 + n/2 = .
2
532 Example Find the sum
12 + 2 2 + 3 2 + · · · + n 2 .
k3 − (k − 1)3 = 3k2 − 3k + 1.
Hence
13 − 0 3 = 3 · 12 − 3 · 1 + 1
23 − 1 3 = 3 · 22 − 3 · 2 + 1
33 − 2 3 = 3 · 32 − 3 · 3 + 1
.. .. ..
. . .
n3 − (n − 1)3 = 3 · n2 − 3 · n + 1
Adding both columns,
n3 − 03 = 3(12 + 22 + 32 + · · · + n2 ) − 3(1 + 2 + 3 + · · · + n) + n.
n(n+1)
From the preceding example 1 + 2 + 3 + · · · + n = ·n2 /2 + n/2 = 2
so
3
n3 − 03 = 3(12 + 22 + 32 + · · · + n2 ) − · n(n + 1) + n.
2
Solving for the sum,
n3 1 n
12 + 2 2 + 3 2 + · · · + n 2 = + · n(n + 1) − .
3 2 3
After simplifying we obtain
n(n + 1)(2n + 1)
(5.5) 12 + 2 2 + 3 2 + · · · + n 2 =
6
116 Chapter 5
1 1 1 1
+ + + ··· + .
1·2 2·3 3·4 99 · 100
Thus
1
1·2
= 11 − 12
1
2·3
= 12 − 13
1
3·4
= 13 − 14
.. .. ..
. . .
1 1 1
99·100
= 99 − 100
Adding both columns,
1 1 1 1 1 99
+ + + ··· + =1− = .
1·2 2·3 3·4 99 · 100 100 100
1 1 1 1
+ + + ··· + .
1 · 4 4 · 7 7 · 10 31 · 34
Thus
1
1·4
= 13 − 12 1
1 1 1
4·7
= 12 − 21
1 1 1
7·10
= 21 − 30
1 1 1
10·13
= 30 − 39
.. .. ..
. . .
1 1 1
34·37
= 102 − 111
Fundamental Sums 117
1 1 1 1 1 1 12
+ + + ··· + = − = .
1 · 4 4 · 7 7 · 10 31 · 34 3 111 37
1 1 1 1
+ + + ··· + .
1 · 4 · 7 4 · 7 · 10 7 · 10 · 13 25 · 28 · 31
Therefore
1 1 1
1·4·7
= 6·1·4 − 6·4·7
1 1 1
4·7·10
= 6·4·7 − 6·7·10
1 1 1
7·10·13
= 6·7·10 − 6·10·13
.. .. ..
. . .
1 1 1
25·28·31
= 6·25·28 − 6·28·31
Adding each column,
1 1 1 1 1 1 9
+ + +· · ·+ = − = .
1 · 4 · 7 4 · 7 · 10 7 · 10 · 13 25 · 28 · 31 6 · 1 · 4 6 · 28 · 31 217
1 · 2 + 2 · 3 + 3 · 4 + · · · + 99 · 100.
1·2 = 31 ·1·2·3− 1
3
·0·1·2
2·3 = 13 ·2·3·4− 1
3
·1·2·3
3·4 = 13 ·3·4·5− 1
3
·2·3·4
.. .. ..
. . .
99 · 100 = 13 · 99 · 100 · 101 − 1
3
· 98 · 99 · 100
Adding each column,
1 1
1 · 2 + 2 · 3 + 3 · 4 + · · · + 99 · 100 = · 99 · 100 · 101 − · 0 · 1 · 2 = 333300.
3 3
Ad Pleniorem Scientiam
Hint:
y 1 1
2
= − .
1−y 1 − y 1 − y2
First Order Recursions 119
Hint: From
tan x − tan y
tan x − tan y =
1 + tan x tan y
deduce that
a−b
arctan a − arctan b = arctan
1 + ab
for suitable a and b.
The order of the recurrence is the difference between the highest and the
lowest subscripts. For example
un+2 − un+1 = 2
is of the first order, and
un+4 + 9u2n = n5
is of the fourth order.
A recurrence is linear if the subscripted letters appear only to the first
power. For example
un+2 − un+1 = 2
is a linear recurrence and
x2n + nxn−1 = 1 and xn + 2xn−1 = 3
are not linear recurrences.
A recursion is homogeneous if all its terms contain the subscripted
variable to the same power. Thus
xm+3 + 8xm+2 − 9xm = 0
is homogeneous. The equation
xm+3 + 8xm+2 − 9xm = m2 − 3
is not homogeneous.
A closed form of a recurrence is a formula that permits us to find the n-th
term of the recurrence without having to know a priori the terms
preceding it.
We outline a method for solving first order linear recurrence relations of
the form
xn = axn−1 + f(n), a 6= 1,
where f is a polynomial.
x0 x1 · · · xn = 7 · 2n x0 x1 x2 · · · xn−1 .
xn = 7 · 2 n .
Aliter: We have:
x0 = 7
x1 = 2x0 + 1
x2 = 2x1 + 1
x3 = 2x2 + 1
.. .. ..
. . .
xn−1 = 2xn−2 + 1
xn = 2xn−1 + 1
Multiply the kth row by 2n−k . We obtain
2 n x0 = 2n · 7
2n−1 x1 = 2n x0 + 2n−1
2n−2 x2 = 2n−1 x1 + 2n−2
2n−3 x3 = 2n−2 x2 + 2n−3
.. .. ..
. . .
22 xn−2 = 23 xn−3 + 22
2xn−1 = 22 xn−2 + 2
xn = 2xn−1 + 1
Adding both columns, cancelling, and adding the geometric sum,
xn = 7 · 2n + (1 + 2 + 22 + · · · + 2n−1 ) = 7 · 2n + 2n − 1 = 2n+3 − 1.
Aliter: Let un = xn + 1 = 2xn−1 + 2 = 2(xn−1 + 1) = 2un−1 . We solve the
recursion un = 2un−1 as we did on our first example:
un = 2n u0 = 2n (x0 + 1) = 2n · 8 = 2n+3 . Finally, xn = un − 1 = 2n+3 − 1.
548 Example Let x0 = 2, xn = 9xn−1 − 56n + 63. Find a closed form for
this recursion.
25 = 9A + B + C,
176 = 81A + 2B + C.
We find A = 2, B = 7, C = 0. The general solution is xn = 2(9n ) + 7n.
1 = A + D,
4 = 3A + B + C + D,
13 = 9A + 4B + 2C + D,
36 = 27A + 9B + 3C + D.
We find A = B = 1, C = D = 0. The general solution is xn = 3n + n2 .
2 = A + B,
7 = 2A + 3B.
We find A = 1, B = 1. The general solution is xn = 2n + 3n .
We now tackle the case when a = 1. In this case, we simply consider a
polynomial g of degree 1 higher than the degree of f.
7 = E,
8 = B + C + E,
10 = 4B + 2C + E.
1 n2 n
We find B = C = , E = 7. The general solution is xn = + + 7.
2 2 2
Aliter: We have
x0 = 7
x1 = x0 + 1
x2 = x1 + 2
x3 = x2 + 3
.. .. ..
. . .
xn = xn−1 + n
Adding both columns,
x0 + x1 + x2 + · · · + xn = 7 + x0 + x2 + · · · + xn−1 + (1 + 2 + 3 + · · · + n).
n(n + 1)
Cancelling and using the fact that 1 + 2 + · · · + n = ,
2
n(n + 1)
xn = 7 + .
2
Ad Pleniorem Scientiam
xn−1 + 4
553 Problem Find a closed form for x0 = 3, xn = .
3
1
Answer: xn = + 2.
3n
Answer: xn = 5n + 5n.
Answer: xn = 6n2 + 6n + 1.
Answer: xn = 2n + 3(5n ).
xn + xn−1 = n2 .
Given that x19 = 94, find the remainder when x94 is divided by 1000.
560 Problem If u0 = 1/3 and un+1 = 2u2n − 1, find a closed form for un .
xn = axn−1 + bxn−2 .
1 = A,
4 = 2A + 2B.
This solves to A = 1, B = 1. The solution is thus xn = 2n + n2n .
Ad Pleniorem Scientiam
an = an−1 + an−2 , a1 = 2, a2 = 3.
571 Example Find a recurrence relation for the number of regions into
which the plane is divided by n straight lines if every pair of lines
intersect, but no three lines intersect.
an = an−1 + n, a1 = 2.
Applications of Recursions 129
In the first case, the two letters r and n are misplaced. Our task is just to
misplace the other n − 2 letters, (1, 2, · · · , r − 1, r + 1, · · · , n − 1) in the
slots (1, 2, · · · , r − 1, r + 1, · · · , n − 1). This can be done in Dn−2 ways.
Since r can be chosen in n − 1 ways, the first case can happen in
(n − 1)Dn−2 ways.
In the second case, let us say that letter r, (1 ≤ r ≤ n − 1) moves to the
n-th position but n moves not to the r-th position. Since r has been
misplaced, we can just ignore it. Since n is not going to the r-th position,
we may relabel n as r. We now have n − 1 numbers to misplace, and this
can be done in Dn−1 ways.
As r can be chosen in n − 1 ways, the total number of ways for the
second case is (n − 1)Dn−1 . Thus Dn = (n − 1)Dn−2 + (n − 1)Dn−1 .
573 Example There are two urns, one is full of water and the other is
empty. On the first stage, half of the contains of urn I is passed into urn II.
On the second stage 1/3 of the contains of urn II is passed into urn I. On
stage three, 1/4 of the contains of urn I is passed into urn II. On stage
four 1/5 of the contains of urn II is passed into urn I, and so on. What
fraction of water remains in urn I after the 1978th stage?
x0 = 1; y0 = 0
x1 = x0 − 21 x0 = 21 ; y1 = y1 + 21 x0 = 1
2
x2 = x1 + 31 y1 = 32 ; y2 = y1 − 31 y1 = 1
3
x3 = x2 − 41 x2 = 21 ; y1 = y1 + 41 x2 = 1
2
x4 = x3 + 51 y3 = 53 ; y1 = y1 − 51 y3 = 2
5
x5 = x4 − 61 x4 = 21 ; y1 = y1 + 61 x4 = 1
2
x6 = x5 + 71 y5 = 74 ; y1 = y1 − 71 y5 = 3
7
x7 = x6 − 81 x6 = 21 ; y1 = y1 + 81 x6 = 1
2
x8 = x7 + 91 y7 = 95 ; y1 = y1 − 91 y7 = 4
9
Ad Pleniorem Scientiam
575 Problem Mrs. Rosenberg has $8 000 000 in one of her five savings
accounts. In this one, she earns 15% interest per year. Find a recurrence
relation for the amount of money after n years.
Applications of Recursions 131
576 Problem Find a recurrence relation for the number of ternary n-digit
sequences with no consecutive 2’s.