brain
tamnd's digital brain — notes, problems, research
43815 notes
Let Algorithm B denote the binary greatest common divisor algorithm (Stein’s algorithm) as described in Section 4.
Let $N$ be a positive integer.
The system is $3x + 7y + 11z = 1,$ $5x - 7y - 3z = 3.$ Eliminating $y$ by adding the two equations gives $8x + 8z = 4,$ hence
Algorithm L, as presented in Section 4.
Let M=2^{n'}, \qquad \Omega=\{x:\; M\le x<2M,\; x\ \text{odd}\}.
We are asked to find an integer $w$ satisfying u \equiv v w \pmod{m}, \quad 0 \le w < m, given positive integers $u$, $v$, $m$, with $v \perp m$.
We are asked to compute an integer $u'$ such that $u u' \equiv 1 \pmod{2^e},$ given that $u$ is odd, i.
Let $u$ and $v$ be random positive integers.
The key correction is that Algorithm X never introduces a “reset” or “nullification” of its working variables at termination.
Let P=\Pr(\gcd(u,v)=1), where $u$ and $v$ are chosen uniformly from the odd positive integers.
Let $u$ and $v$ range uniformly over the integers $1 \le u, v \le n$.
We correct both parts, and in particular replace the unjustified interchange of limit and infinite sum by a derivation that keeps all sums finite until the final asymptotic step.
Let $q_n$ denote the number of ordered pairs $(u,v)$ with $1 \le u,v \le n$ and $\gcd(u,v)=1$.
We are asked to compute $\gcd(31408, 2718)$ using Algorithm B and then to find integers $m$ and $n$ such that $31408 \, m + 2718 \, n = \gcd(31408, 2718)$ using Algorithm X.
Program B in Section 4.
The exercise statement as given is incomplete.
Let $u$ and $v$ be independent random positive integers chosen with uniform density over the positive integers.
Let's carefully analyze the previous Python solution.
Let $u$ and $v$ be positive integers, with canonical prime factorizations u = \prod_{p \text{ prime}} p^{u_p}, \qquad v = \prod_{p \text{ prime}} p^{v_p}, where all but finitely many of the exponents...
Assume first that $u=0$.
Let n = \prod_{p} p^{a_p} be the canonical prime factorization of $n$, where each $a_p \ge 0$ and all but finitely many $a_p$ are zero.
I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.
Suppose $1 \le u' < 2^k$ and $1 \le v' < 2^k$, and assume that $\lfloor 2^{2k} u/u' \rfloor = \lfloor 2^{2k} v/v' \rfloor.$ Let $x = 2^{2k} u/u'$ and $y = 2^{2k} v/v'$.
**Solution.
Representing $(1/0)$ and $(-1/0)$ as $\infty$ and $-\infty$ corresponds to adjoining two signed points at infinity to the set of rational numbers.
**Exercise 4.
The recommended division method is the direct fraction-division algorithm.
Let \frac{u}{u'} \div \frac{v}{v'}, where $u \perp u'$ and $v \perp v'$.
Let d=\gcd(u,v), and define
The previous solution does not address the exercise at all.
Let a=\gcd(u,v'), \qquad b=\gcd(u',v).
Let $b$ and $B$ be the bases as in the problem statement.
Let $u = (u_7 \ldots u_1 u_0)_{10}$ be a decimal number, and let $U = (u_7 \ldots u_1 u_0)_{16}$ denote its binary-coded decimal (BCD) representation.
The error in the previous code is actually two-fold: first, the test harness had a syntax error (a dangling comma in the last `assert`).
Exercise 4.
Let u=(u_m u_{m-1}\ldots u_1u_0)_{10} be the decimal number to be converted into binary notation.
The error in the previous code is actually two-fold: first, the test harness had a syntax error (a dangling comma in the last `assert`).
Let the input be an $n$-digit decimal integer N=\sum_{i=0}^{n-1} a_i 10^i, \qquad 0\le a_i\le 9.
Let $u$ be a nonnegative integer represented in binary-coded decimal (BCD) form as $u = u_{n-1} u_{n-2} \ldots u_1 u_0,$ where each $u_j$ occupies four bits and satisfies $0 \le u_j \le 9$.
**Exercise 4.
Method 1b already provides the key idea.
Define v_0(u)=3\lfloor u/2\rfloor+3, and
Equation (5) shows how to replace division by $10$ with multiplication by an approximation to $\frac1{10}$.
Methods 1a, 1b, 2a, and 2b are stated for positive radices $b$ and $B$.
Let \delta=r-\alpha .
**Exercise 4.
The statement uses the symbol $\epsilon$ but the data are $u$ and $v$; the intended meaning is that $v$ is the allowed error bound.
A radix conversion routine transforms a nonnegative integer written in one base into its representation in another base.
Let the mixed-radix system have radices r_0,r_1,\ldots,r_{n-1}, so that a number is represented in the form
Method 1b evaluates u=a_m b_{m-1}\cdots b_0+\cdots+a_1 b_0+a_0 by Horner's rule,
Let K_1=1,\qquad K_{2n}=3K_n,\qquad K_{2n+1}=2K_{n+1}+K_n \qquad (n\ge1).
There is actually **no algorithmic bug** in the output you showed.
The error message is very explicit: `NameError: name 'math' is not defined`.
Start with the DFT \hat{u}_t=\sum_{s=0}^{K-1} u_s \,\omega^{st}, \quad \omega=e^{-2\pi i/K}.
We restart from a clean formulation and give a model-independent analysis of what “fastest online multiplication” means in each automaton class.
**Solution (Corrected)** We are asked to implement the Fourier-transform multiplication method efficiently on a pointer machine and show that $m$-bit multiplication can be done in $O(m)$ steps.
**Exercise 4.
Let the two $n$-bit numbers be A = \sum_{i=0}^{n-1} a_i 2^i, \quad B = \sum_{j=0}^{n-1} b_j 2^j.
**Corrected Solution** We want to show that all complex numbers $A^{(j)}$ computed during the third Fourier transform (the computation of $\tilde{w}_s$) satisfy $|A^{(j)}| < 1$.
**Corrected Solution to Exercise 4.
The statement is **false**.
Let $U(x)$ and $V(x)$ be polynomials of degree $r$ with integer coefficients, and let $W(x) = U(x)V(x),$ so $W(x)$ has degree at most $2r$.
Let $\ell(n)$ denote the binary length of $n$, i.
We are asked to track a frog moving along a one-dimensional axis starting at position 0.
**Corrected Solution for Exercise 4.
This is no longer a Codeforces 1535C input issue.
**Exercise 4.
Thank you, now the issue is fully clear.
Let $x$ be an $n$-digit automorph, so the last $n$ digits of $x^2$ equal $x$.
We are asked to compute w = (uv) \bmod (2^q - 1) for two $q$-bit integers $u$ and $v$ given in the mixed-radix representation
The claimed output `10` for `"0?
Suppose an integer $u$ lies in the symmetrical range $-\frac{m}{2} < u < \frac{m}{2}, \qquad m = m_1 m_2 \cdots m_r, \eqno(10)$ and we seek numbers $u_1, \ldots, u_r$ such that $u \equiv u_j \pmod{m_j...
From the construction of mixed-radix digits in (25), the integer $u$ is represented in the form u \equiv v_1 + m_1 v_2 + m_1 m_2 v_3 + \cdots + m_1 m_2 \cdots m_{r-1} v_r \pmod{m}, and for each $j$ th...
Let $m_1, m_2, \ldots, m_r$ be odd integers, and let $u = (u_1, \ldots, u_r)$ satisfy $0 \le u < m$, where $m = m_1 m_2 \cdots m_r$, and suppose that $u$ is even.
Equation (24) in _The Art of Computer Programming_, Volume 2, Section 4.
The reviewer is correct that the previous submission is unrelated to the stated TAOCP exercise.
Edit Let m=2^g-1.
The solution does not correctly determine the outcome of the greedy procedure in part (a).
Let m=\operatorname{lcm}(m_1,m_2,\ldots,m_r).
We are asked whether Theorem C from _The Art of Computer Programming_ would still hold if the variables $a$, $u_1, u_2, \dots, u_r$, and $u$ were allowed to be arbitrary real numbers instead of intege...
Equation (13) is obtained by the rule stated immediately before it.
Find all integers $u$ satisfying u \equiv 1 \pmod 7, \qquad u \equiv 0 \pmod{11}, \qquad
The desired value of $w$ is the nearest integer to $uv/255$.
Let u_i=(u_{i,n-1}\cdots u_{i,1}u_{i,0})_b, \qquad 0\le u_i<b^n, and let
We are given a directed graph whose vertices are cities and whose root is city 1, the capital.
Let $u$ be a $2n$-place number and $v$ an $n$-place number in base $b$, with $0 \le u < b^{2n}$, $0 \le v < b^n$, and assume $u = vq$ so the remainder is zero.
The solution attempts to prove the lower bound on the true remainder when the trial quotient $\hat q$ underestimates the true quotient $q$ by 1.
Let $x = uv$, where $0 \le u,v < 2^n$.
In Algorithm D, step D1 multiplies both the dividend and the divisor by the same power of $b$ so that the leading digit of the divisor satisfies $v_{n-1} \ge \lfloor b/2 \rfloor$.
Let \(\phi\) be given to \(n\) digits of precision in a fixed radix \(b\).
A correct solution must design algorithms, not analyze radix transformations.
A correct design must first remove the ambiguity about what “word-level scaling” means and then express every operation in terms of explicit operations on fixed-size word arrays.
**Solution to Exercise 4.
Assume first that $v \ne 0$.
In Algorithm A, each digit $w_j$ is computed from the expression $u_j + v_j + k$, where $k$ is the carry from the previous position.
The claim is: > At the beginning of step D3 of Algorithm D, we always have $u_{j+n} = 0$.
Let $v = (.v_{n-1}\,v_{n-2}\,\ldots v_1\,v_0)_b$ with $v_{n-1} \ne 0$.
**Solution to Exercise 4.
Step D8 in Program D performs the correction after an over-subtraction in the trial quotient step of the division algorithm.
**Corrected Solution to Exercise 4.