CS311H Syllabus Calendar Office Hours Readings Assignments Resources

CS311H Discrete Mathematics for Computer Science

Quiz 07 Solutions

Oct 23, 2026


Problem 1: Cartesian Countability

Prove that \(\mathbb{Z^+}\times\mathbb{Z^+}\) is a countable set, by proving that the function \(f: \mathbb{Z^+}\times\mathbb{Z^+} \rightarrow \mathbb{Z}\) where \(f(m,n) = \frac{(m+n-2)(m+n-1)}{2}\) is a bijection.

Show solution

Part 1: the function as stated is not a bijection.

Not injective. We have \((1,2) \neq (2,1)\), but

\[ \begin{array}{r c l} f(1,2) & = & \frac{(1+2-2)(1+2-1)}{2} = \frac{1 \cdot 2}{2} = 1, \\ f(2,1) & = & \frac{(2+1-2)(2+1-1)}{2} = \frac{1 \cdot 2}{2} = 1. \end{array} \]

So \(f(1,2) = f(2,1)\), and \(f\) is not one-to-one. In fact \(f(m,n)\) depends only on \(m+n\), so \(f\) is constant on each diagonal \(\{(m,n) : m+n=s\}\), which contains \(s-1\) pairs.

Not surjective. For positive integers \(m,n\) we have \(m+n-2 \geq 0\) and \(m+n-1 \geq 1\), so \(f(m,n) \geq 0\). Hence no pair is mapped to \(-1 \in \mathbb{Z}\). (More precisely, \(f(m,n) = T(m+n-2)\) where \(T(j) = \frac{j(j+1)}{2}\), so \(f\) only takes the triangular numbers \(0, 1, 3, 6, 10, \dots\); for example, \(2\) is never attained.)

Since \(f\) is neither injective nor surjective, \(f\) is not a bijection. So the proof the problem asks for cannot be carried out with this \(f\).

Part 2: a correct bijection.

The problem is that \(f\) cannot tell apart the pairs on the same diagonal. Adding \(m\) fixes this. Define \(g: \mathbb{Z^+}\times\mathbb{Z^+} \rightarrow \mathbb{Z^+}\) by

\[ g(m,n) = \frac{(m+n-2)(m+n-1)}{2} + m. \]

This is the Cantor pairing function. It lists the pairs diagonal by diagonal: \(g(1,1)=1,\ g(1,2)=2,\ g(2,1)=3,\ g(1,3)=4,\ g(2,2)=5,\ g(3,1)=6, \dots\)

Problem 2: Euclidean Algorithm

  1. For positive integers \(m,n\), prove that \(\gcd(2^m - 1, 2^n-1) = 2^{\gcd(m,n)} -1\).
  2. Prove that \(k\) and \(k+1\) are relatively prime, when \(k>1\) is an integer.
Show solution

(a) Solution 1: strong induction

Proof. Let \(m,n\) be positive integers. We do strong induction on \(s=m+n\).

Let \(s\in\mathbb{Z}, s\geq 2\). Define \(P(s)\) as: for all positive integers \(m,n\) with \(s = m+n\), \(\gcd(2^m-1, 2^n-1) = 2^{\gcd(m,n)}-1\).

Base Case: \(m=1, n=1\) or \(P(2)\). Then, \(\gcd(2^m - 1, 2^n-1) = \gcd(2^1-1, 2^1-1) = \gcd(1,1) = 1\). We also have \(2^{\gcd(m,n)} -1 = 2^{\gcd(1,1)}-1 = 2^1 - 1 = 1\). So, \(\gcd(2^m - 1, 2^n-1) = 2^{\gcd(m,n)} -1\). Thus, the base case is proven.

Inductive Step:

IH: Let \(k\in\mathbb{Z}, k\geq 2\) and assume \(P(t)\) holds for all integers \(t\) such that \(2\leq t\leq k\).

We need to show that \(P(k+1)\) holds. Let \(m,n\) be positive integers such that \(m+n=k+1\). We have two cases.

Case 1: \(m=n\). Then, we have \(\gcd(2^m-1, 2^n-1) = \gcd(2^m-1, 2^m-1) = 2^m-1\), and \(2^{\gcd(m,n)}-1 = 2^{\gcd(m,m)}-1 = 2^m-1\). Thus, \(\gcd(2^m-1, 2^n-1) = 2^{\gcd(m,n)}-1\).

Case 2: \(m\neq n\). WLOG, assume \(m>n\). Note that \(2^{m}-1 = 2^{m-n}(2^n-1)+(2^{m-n}-1)\).

By Euclidean Algorithm, \(\gcd(a,b) = \gcd(a-cb,b)\) for integers \(a,b,c\). Applying \(a = 2^m-1\), \(b = 2^n-1\) and \(c=2^{m-n}\) yields \(\gcd(2^m-1, 2^n-1) = \gcd(2^{m-n}-1, 2^n-1)\).

Since \(m>n\geq 1\), each integer in the pair \((m-n,n)\) is positive, and \((m-n)+n = m\). Also \(m \geq 2\) (because \(m>n\geq 1\)), and \(m < m+n = k+1\). So \(2 \leq m \leq k\), and we can apply the IH, with \(t=m\), to get that \(\gcd(2^{m-n}-1, 2^n-1) =2^{\gcd(m-n,n)}-1\).

By Euclidean Algorithm, \(\gcd(m,n) = \gcd(m-n,n)\), so we have \(\gcd(2^{m-n}-1, 2^n-1) =2^{\gcd(m,n)}-1\). Thus, the inductive step is proven.

Then, by strong induction, \(P(s)\) holds for all \(s\geq 2\).


(a) Solution 2 (alternate): without induction

Let \(g=\gcd(m,n)\) and \(d=\gcd(2^m-1,\,2^n-1)\). We show that \(d\) and \(2^g-1\) divide each other.

Facts assumed.

  1. For an integer \(x\) and a positive integer \(q\), \(x^q-1=(x-1)(x^{q-1}+x^{q-2}+\cdots+x+1)\). In particular, \(x-1\mid x^q-1\).
  2. (Bézout's identity) For positive integers \(m,n\), there are integers \(x,y\) such that \(\gcd(m,n)=xm+yn\).
  3. Every common divisor of two integers divides their \(\gcd\).
  4. If \(a\equiv b \pmod{d}\), then \(a^k\equiv b^k \pmod{d}\) for every integer \(k\geq 0\), and congruences modulo \(d\) can be multiplied.
  5. If two positive integers each divide the other, they are equal.

Step 1: \(2^g-1\) divides \(d\). Since \(g\mid m\), we can write \(m=gq\) for a positive integer \(q\). Then \(2^m-1=(2^g)^q-1\), which is divisible by \(2^g-1\) by Fact 1. The same argument with \(g\mid n\) shows \(2^g-1\mid 2^n-1\). So \(2^g-1\) is a common divisor of \(2^m-1\) and \(2^n-1\), and by Fact 3, \(2^g-1\mid d\).

Step 2: \(d\) divides \(2^g-1\). By Fact 2, \(g=xm+yn\) for some integers \(x,y\). For any integer \(t\) we also have

\[ g=(x+tn)m+(y-tm)n. \]

Choose \(t\) large enough that \(a=x+tn\geq 1\), and let \(b=tm-y\), so that \(g=am-bn\). Since \(g\leq m\leq am\), we get \(bn=am-g\geq 0\), so \(b\geq 0\). Thus

\[ g=am-bn, \qquad a\geq 1,\ b\geq 0 \text{ integers}. \]

Since \(d\mid 2^m-1\) and \(d\mid 2^n-1\), we have \(2^m\equiv 1 \pmod{d}\) and \(2^n\equiv 1 \pmod{d}\). Then (all congruences below are modulo \(d\)):

\[ \begin{array}{c l l} & 1 & \\ \equiv & (2^m)^a & \langle 2^m\equiv 1 \text{ and Fact 4} \rangle \\ = & 2^{am} & \langle \text{laws of exponents} \rangle \\ = & 2^{g+bn} & \langle am=g+bn \rangle \\ = & 2^g\cdot (2^n)^b & \langle \text{laws of exponents} \rangle \\ \equiv & 2^g\cdot 1^b & \langle 2^n\equiv 1 \text{ and Fact 4} \rangle \\ = & 2^g. & \langle \text{algebra} \rangle \end{array} \]

So \(2^g\equiv 1 \pmod{d}\), that is, \(d\mid 2^g-1\).

Conclusion. Both \(d\) and \(2^g-1\) are positive and each divides the other, so by Fact 5, \(d=2^g-1\). Therefore \(\gcd(2^m-1,2^n-1)=2^{\gcd(m,n)}-1\).


(b)

For the sake of contradiction, assume that \(k\) and \(k+1\) have a common divisor other than \(1.\) Let this common divisor be \(d\) and \(d > 1.\)

Since \(d\) divides both \(k\) and \(k+1\), \(d \mid \left((k+1) - k\right)\). But \((k+1) - k =1.\) Therefore, \(d \mid 1,\) so \(d=1.\) This contradicts our assumption that \(d > 1.\) Therefore, \(k\) and \(k+1\) are relatively prime.

(The argument never uses \(k>1\), so it holds for every integer \(k\geq 1\).)

Problem 3: True False

  1. If \(f\) is a polynomial function with integer coefficients and \(a\equiv b\pmod{m}\), then \(f(a)\equiv f(b)\pmod{m}\).
    Show answer

    TRUE

  2. The modular multiplicative inverse of \(a\pmod{m}\) is defined as \(a^{-1}\) such that \(aa^{-1}\equiv 1\pmod{m}\). An inverse always exists.
    Show answer

    FALSE

  3. If the above inverse exists, it is unique.
    Show answer

    FALSE

  4. If \(a\) and \(m\) are relatively prime, then \(a^2\equiv 1\pmod{m}\).
    Show answer

    FALSE

  5. If \(a^k\equiv1\pmod{m}\) for some positive even integer \(k\), then \(a^{k/2}\equiv1\pmod{m}\).
    Show answer

    FALSE

  6. The set of all rational numbers between \(0\) and \(1\) is countable.
    Show answer

    TRUE

  7. The set of all finite subsets of \(\mathbb{N}\) is countable.
    Show answer

    TRUE

  8. The power set of \(\mathbb{N}\) is countable.
    Show answer

    FALSE

  9. The set of all functions \(f:\mathbb{N}\to\{0, 1\}\) is countable.
    Show answer

    FALSE

  10. The set of frequencies of all visible colors is countable.
    Show answer

    FALSE