brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 4.5.4 Exercise 44

**Solution.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 43

Let m=pq be a Blum integer, with

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 40

We are asked to consider an abstract computer that can perform the operations $x + y$, $x - y$, $x \cdot y$, and $\lfloor x/y \rfloor$ on integers $x$ and $y$ of arbitrary length in one unit of time,...

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.4 Exercise 41

The requested solution is a standalone writeup, so I am providing it in a writing block.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 37

Let $N = pq$ where $p \equiv 3 \pmod 8$ and $q \equiv 7 \pmod 8$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 38

The reviewer’s objections are correct.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.4 Exercise 39

We are asked to find a long chain of *successive primes*, where a prime \(q\) is a successor of a prime \(p\) if \[ q = 2^k p + 1 \] for some integer \(k \ge 0\), and both \(p\) and \(q\) are prime.

taocpmathematicsalgorithmsvolume-1project
TAOCP 4.5.4 Exercise 35

Let $N = pq$ where $p \equiv 3 \pmod 8$ and $q \equiv 7 \pmod 8$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 36

Equation (22) has the form T(m)\asymp m+\frac{\ln N}{\ln m}, up to multiplicative factors that vary only slowly with $m$.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.4 Exercise 34

Let $N = pq$ be the product of two distinct primes, as in the RSA scheme.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 33

**Statement.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.5.4 Exercise 30

Let $N$ be an odd positive integer with prime factorization N = q_1^{f_1} \cdots q_d^{f_d}, where the $q_i$ are distinct primes and $f_i \ge 1$.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.5.4 Exercise 31

We are asked to use exercise 1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 32

Suppose RSA uses public exponent $e=3$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 29

Let S(n)=\{\,p_1^{e_1}p_2^{e_2}\cdots p_m^{e_m}\le n : e_i\ge0\,\}.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 28

Let $Q(A,B)=A^2-dB^2,$ and let $v_p(n)$ denote the exponent of the prime $p$ in $n$, with the convention that $v_p(n)=k \iff p^k\mid n,\quad p^{k+1}\nmid n.$ The quantity to be determined is $f(p,d)=\...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 26

Let N=fr+1,\qquad 0<r\le f+1, and suppose that for every prime divisor $p$ of $f$ there exists an integer $x_p$ such that

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 27

Let N=5\cdot 2^n+1, and let

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 25

The statement as printed in the exercise contains a typographical problem in the oscillatory term.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.4 Exercise 24

Let $S = {n : 1 < n \le N,\ n\ \text{odd},\ n\ \text{composite}}$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 23

Let $p \ge 0$ be an integer and $q > 1$ an odd integer.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 21

Let $p$ be a prime number, and consider Algorithm B from Section 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 22

Let $n\ge 3$ be odd, and let $p_n$ be the probability that Algorithm P declares $n$ to be prime when $n$ is actually composite.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 19

Let $D$ be given and let $p$ be any odd prime such that $p-1 \mid D$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 18

Let $p_n$ and $p_{n-1}$ denote the two largest prime factors in a typical factorization, ordered so that $p_{n-1} \le p_n$.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.4 Exercise 20

Let $D$ be a given positive integer, and let $p$ range over odd primes.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.5.4 Exercise 16

A **Mersenne prime** is a prime number of the form $M_p = 2^p - 1,$ where $p$ itself is prime.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.5.4 Exercise 17

The proof proceeds by structural induction on the Pratt tree.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 15

Let $P$ and $Q$ be integers with $\gcd(P,Q) = 1$, and define the Lucas sequence $(U_n)$ by $U_0 = 0, \quad U_1 = 1, \quad U_{n+1} = P U_n - Q U_{n-1} \quad (n \ge 1).$ Let $N$ be a positive integer su...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 14

We are asked to prove that the number $T$ computed in step E3 of Algorithm E (the strong pseudoprime test in Section 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 12

Let N=p_1^{a_1}p_2^{a_2}\cdots p_d^{a_d}, where $p_1,\ldots,p_d$ are the distinct prime factors of $N$.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.4 Exercise 10

Let $n>1$ satisfy the hypothesis: for every prime $p \mid (n-1)$ there exists an integer $x_p$ such that x_p^{(n-1)/p} \equiv 1 \pmod n, \qquad x_p^{n-1} \not\equiv 1 \pmod n.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 11

We are asked to determine the outputs of Algorithm E when N = 197209, \quad k = 5, \quad m = 1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 8

**Exercise 4.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.4 Exercise 9

Let $n$ be an odd integer, $n \ge 3$, and suppose that $\lambda(n)$, the Carmichael function of $n$ defined in Theorem 3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 6

We are asked to count the number of integers $x$ with $0 \le x < p$ such that the congruence x^2 - N \equiv y^2 \pmod p has a solution $y$, where $p$ is an odd prime and $p \nmid N$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 7

Algorithm D (Fermat's method) involves iterative calculations modulo various integers $m_i$ to test for squares and compute factors of a number $N$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.4 Exercise 3

Let us construct a number $P$ with the desired property.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.4 Exercise 5

The review correctly identifies the central failure: the solution never completes Fermat’s method by producing an actual $x$, $y$, and hence never factors $11111$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.4 Exercise 4

**Exercise 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.4 Exercise 2

Step A2 of Algorithm A tests whether the current value of $n$ is equal to $1$, and if so, terminates the algorithm.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.5.3 Exercise 42

**Corrected Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 41

Let K=\sum_{n\ge 0}2^{-2^{n}} =\frac12+\frac14+\frac1{16}+\frac1{256}+\cdots .

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.4 Exercise 1

In Algorithm A the invariant at step A1 states that $n$ has no prime factors less than $d_k$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.5.3 Exercise 39

Let $h$ be the number of hits and $a$ the number of times at bat.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 38

Let L(n)=\max_{m\ge 0}T(m,n), where $T(m,n)$ is the number of division steps performed by Euclid's algorithm on inputs $u=m$, $v=n$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 37

Let $a_1, \ldots, a_n$ be positive integers.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.3 Exercise 35

Let S(n)=\sum_{1\le m<n}s(m,n), where $s(m,n)$ denotes the sum of the partial quotients in the simple continued fraction of $m/n$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.3 Exercise 36

Let g_k=\gcd(u_1,\ldots,u_k)\qquad (1\le k\le n).

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 34

Let $h_0(n)$ be the number of representations of $n$ as in Exercise **33** such that $d < x'$, plus half the number of representations with $2d = x'$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.3 Exercise 32

(a) A Morse code sequence of length $n$ consists of $r$ dots and $s$ dashes with $r + 2s = n$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.3 Exercise 31

Let the modified algorithm be defined as follows.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 29

To produce a fully corrected solution, we must work strictly with the exercise instructions.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 30

Let u=qv+r,\qquad 0\le r<v.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.3 Exercise 28

We prove each of the identities in turn.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 27

The statement of the exercise depends on the explicit forms of equations (43), (54), and (55) in Section 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 25

We are asked to construct a set \mathcal{I} = I_1 \cup I_2 \cup I_3 \cup \cdots \subseteq [0,1], where the $I_k$ are **pairwise disjoint intervals**, such that identity (45) fails.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.3 Exercise 26

Let $n \ge 2$ be an integer, and consider the fractions \frac{k}{n}, \quad 1 \le k \le \lfloor n/2 \rfloor.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 24

Let $X$ be a real number chosen uniformly at random from the interval $[0,1)$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 22

We are asked to develop efficient methods for approximating the quantities $\lambda_1$ and $\Psi_2(x)$ in equation (44) of [_HM46_], for small $y \ge 3$ and $0 \le x \le 1$.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.3 Exercise 23

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.3 Exercise 20

Let $K_n(x_1,\dots,x_n)$ denote the continuant defined in Section 4.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.3 Exercise 21

The issue here is that the "Actual output" is empty, which usually indicates that the code is reading input incorrectly.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.3 Exercise 19

Equation (24) is F(x)=\sum_{m\ge1}\left(F\!

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 18

**Exercise 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 17

By definition (2), \begin{aligned} //x_1,-x_2// &= \frac{1}{x_1+\frac1{-x_2}} = \frac{1}{x_1-\frac1{x_2}}

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 15

Let $x = //x_1, x_2, x_3, \ldots//$ be a regular continued fraction in the sense of equation (10).

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 14

Let $X = //A_0, A_1, A_2, \ldots//$ be the regular continued fraction of a real number $X$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 12

Let $X = (\sqrt{D} - U)/V$ be a quadratic irrationality, where $D$, $U$, $V$ are integers, $D > U^2 \ne 0$, $D$ is not a perfect square, and $V$ divides $D - U^2$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 13

Unusual activity has been detected from your device.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.3 Exercise 11

Let X=A_0+//\!

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 10

**Exercise 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 8

We restart from the structural identity behind regular continued fractions: each partial quotient corresponds to a Möbius transformation, and the continuant formulas encode their matrix products.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 9

Let C(x_1,\ldots,x_n)=//x_1,\ldots,x_n// denote the continued fraction defined recursively by

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 5

Let C_n = //x_1,x_2,\ldots,x_n// = \frac{p_n}{q_n} be the $n$-th convergent, where $p_n,q_n$ are continuants.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.3 Exercise 7

Let $K_n(x_1, x_2, \ldots, x_n)$ denote the continuant polynomial defined by equation (4) in Section 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 6

First consider the infinite continued fraction X=//B_1,B_2,\ldots//, where each $B_n$ is a positive integer.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 4

We are asked to prove equation (8) of Section 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 3

Let M_n = \begin{pmatrix} x_1 & 1 & 0 & \cdots & 0 \\ -1 & x_2 & 1 & & \vdots \\

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 2

We are asked to compute the product of the 2×2 matrices M_0 \cdot M_1 \cdot M_2 \cdots M_n, where

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 1

First we verify that the proposed program is correct.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.2 Exercise 41

Let $m$ and $n$ be nonnegative integers.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 42

Let $n$ be a positive integer.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 40

Let M=\max(|u|,|v|) at the moment Algorithm K begins.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 38

Exercise 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 39

**Problem.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 36

The previous solution must be discarded.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 37

**Solution.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 4.5.2 Exercise 34

Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.2 Exercise 33

Let $H(a,b)$ denote the number of iterations of Harris's algorithm.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.5.2 Exercise 32

Let $G$ be a continuous function on $[0,1]$ satisfying equations (36) and (37).

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.2 Exercise 31

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.2 Exercise 30

We are asked to determine $G_2(x)$, the cumulative distribution function of the ratio r_2 = \frac{\min(u_2,v_2)}{\max(u_2,v_2)} after the second subtract-and-shift cycle of Algorithm B, continuing fro...

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.2 Exercise 28

Exercise 27 established equation (58), expressing $\psi_n$ in terms of Bernoulli numbers.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.2 Exercise 29

Let R=\frac{\min(u,v)}{\max(u,v)}\in[0,1].

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.2 Exercise 27

The proposed solution correctly identifies the probability requested: the probability that a single subtract-and-shift cycle produces an odd value $w$ in the range $[2^n,2^{n+1})$ while the other argu...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 26

Let \Delta(x)=2G(x)-5G(2x)+2G(4x).

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 23

Solution to TAOCP 4.5.2 Exercise 23.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 24

We restart from the correct probabilistic model and explicitly connect the “next time step B6 is encountered” to Brent’s limiting distribution.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 25

Equation (46) in the text gives a relation between the series 1 + \rho_1 t + \rho_2 t^2 + O(t^3) and the exponential factor with a quadratic correction:

taocpmathematicsalgorithmsvolume-1math-medium