brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 7.2.1.1 Exercise 34

Let $x \in [0,1)$ and write its dyadic expansion x = 0.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 33

Let $x \in [0,1)$ and write its dyadic expansion x = 0.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 32

Let $x \in [0,1)$ and write its dyadic expansion x = 0.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 31

Let $G$ be the Cayley graph of the symmetric group $S_n$ with generators $(\alpha_1,\dots,\alpha_k)$, and assume that each generator satisfies \alpha_j(x)=y for fixed distinct symbols $x,y \in {1,\dot...

taocpmathematicsalgorithmsvolume-4hm-hard
TAOCP 7.2.1.1 Exercise 30

Let $G$ be the Cayley graph of $S_n$ with generating set \{\sigma,\tau\}, \qquad \sigma = (1\,2\,\dots\,n), \quad \tau = (1\,2), where $n \ge 3$ is odd.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 29

Let $G$ be the Cayley graph of $S_n$ with generating set \{\sigma,\tau\}, \qquad \sigma = (1\,2\,\dots\,n), \quad \tau = (1\,2), where $n \ge 3$ is odd.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 28

Let $G$ be the Cayley graph of all permutations of ${1,\dots,n}$ generated by the three involutions \rho = (1\,2)(3\,4)(5\,6)\cdots,\quad \sigma = (2\,3)(4\,5)(6\,7)\cdots,\quad \tau = (3\,4)(5\,6)(7\...

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 27

Let $G$ be the Cayley graph of all permutations of ${1,\dots,n}$ generated by the three involutions \rho = (1\,2)(3\,4)(5\,6)\cdots,\quad \sigma = (2\,3)(4\,5)(6\,7)\cdots,\quad \tau = (3\,4)(5\,6)(7\...

taocpmathematicsalgorithmsvolume-4medium
CF 103698E - Sequence

We are given a system that builds a sequence step by step starting from a fixed first value. At each next position, the value is determined by one of two deterministic transformations applied to the previous element: either we increase it by a fixed constant or we replace it…

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 26

Let Algorithm E be the permutation generator defined in Section 7.

taocpmathematicsalgorithmsvolume-4medium
CF 103698D - Matrix

We are given a grid of size $n times m$. Each cell of the grid is either 0 or 1. The grid is not arbitrary: it must satisfy a global consistency rule that ties each cell to the parity structure of its row and column.

codeforcescompetitive-programming
CF 103698H - Virus Experiment

We are given a tree with n nodes. Each edge has a label, one of four characters, representing a transformation applied when a “signal” travels through that edge.

codeforcescompetitive-programming
CF 103698C - The 80/20 Rule

We are given a collection of bank accounts, each holding some amount of money. The task is not to optimize over subsets in the usual sense, but to understand how “uneven” the distribution can be made when we group people into a prefix of the sorted population versus its…

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 25

Let $g(k)=k\oplus \lfloor k/2\rfloor$, and write the binary expansions k=(\dots b_2 b_1 b_0)_2,\qquad g(k)=(\dots a_2 a_1 a_0)_2, with the standard Gray relations from (7.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 24

The flaw in the previous solution is the attempt to treat an infinite XOR as a topological limit inside the product space.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 23

Let $g(k) = (\ldots a_2 a_1 a_0)_2$ and $k = (\ldots b_2 b_1 b_0)_2$, with the relation from (7), a_j = b_j \oplus b_{j+1}, \quad j \ge 0.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 22

Each leaf of the given binary trie represents a right subcube, that is, a set of binary $n$-tuples obtained by fixing some coordinates along the root-to-leaf path and leaving the remaining coordinates...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 21

Let $\alpha(n)$ denote the English name of $n$ written as a concatenation of capital letters, and interpret a pure alphametic as a bijection from letters to digits ${0,1,\dots,9}$ such that the corres...

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 20

The earlier solution fails because it assumes structural facts about the octacode without grounding them in the construction from the previous exercise.

taocpmathematicsalgorithmsvolume-4math-project
TAOCP 7.2.1.1 Exercise 19

Let $g(x)=x^3+2x^2+x-1$ in $\mathbb{Z}_4[x]$, so $-1\equiv 3 \pmod 4$, hence g(x)=x^3+2x^2+x+3.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 18

Define a mapping $\varphi : {0,1,2,3} \to {0,1}^2$ by \varphi(0) = (0,0), \quad \varphi(1) = (0,1), \quad \varphi(2) = (1,1), \quad \varphi(3) = (1,0).

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 17

Let $\Gamma_3 = g(0), g(1), \dots, g(7)$ denote the 3-bit Gray binary code from Section 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 16

Let $V={0,1,\dots,2n}$ be the node set, and let a binary $n$-tuple $(a_1,\dots,a_n)$ be represented by the directed cycle defined by the LINK fields 0 \to 1+n a_1 \to 2+n a_2 \to \cdots \to n+n a_n \t...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 15

Consider the rooted ordered tree whose nodes are all strings $a_1 \dots a_j$ with $0 \le j \le n$ and $0 \le a_i < m_i$ for $1 \le i \le j$.

taocpmathematicsalgorithmsvolume-4medium
CF 103698G - Palinomial

We are given $n$ polynomials, each described by its coefficients in increasing degree order. Then we answer $q$ queries, each query giving an interval $[l, r]$.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 14

No exercise statement is included after “Write the solution now.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 13

No exercise statement is included after “Write the solution now.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 12

No exercise statement is included after “Write the solution now.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 112

No exercise statement is included after “Write the solution now.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 111

Let a _representation_ be any expression obtained from the digit string $123456789$ by inserting either $+$, $-$, or concatenation between consecutive digits.

taocpmathematicsalgorithmsvolume-4medium
CF 103698F - Tree

The task can be understood as a classic linear-algebraic counting problem on an undirected graph. Instead of reasoning combinatorially about spanning trees directly, we reinterpret the graph through a matrix built from its structure and compute a determinant that encodes the…

codeforcescompetitive-programming
CF 103698B - Majhong

The task describes a simplified Mahjong-like system where tiles are numbered from 1 to n, and each number can appear in any quantity. The entire hand is just a multiset of these numbers. We are also given two parameters that define what counts as a valid group.

codeforcescompetitive-programming
CF 103708L - The last problem

I can’t write a correct editorial for Codeforces 103708L - The last problem because the actual problem statement is missing from your prompt.

codeforcescompetitive-programming
CF 103708I - Isabel's Divisions

The task revolves around a single integer written as a sequence of digits. From this number, we inspect each digit and check whether that digit can serve as a divisor of the entire number. We ignore any digit that is zero, since division by zero is undefined.

codeforcescompetitive-programming
CF 103708K - Kilo Waste

I can’t produce a correct, meaningful editorial for Codeforces 103708K - Kilo Waste yet because the actual problem statement, input format, and output specification are missing from your prompt.

codeforcescompetitive-programming
CF 103708H - Hog Fencing

I don’t have the actual problem statement for “Codeforces 103708H - Hog Fencing”, so I can’t reliably reconstruct the task, constraints, or intended solution.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 110

Let $T_n$ denote the number of steps in the shortest procedure that removes all $n$ rings from the bar and then restores them, when the two smallest rings may be taken on or off simultaneously.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 11

Let $T_n$ denote the number of steps in the shortest procedure that removes all $n$ rings from the bar and then restores them, when the two smallest rings may be taken on or off simultaneously.

taocpmathematicsalgorithmsvolume-4math-medium
CF 103708J - Jeffrey's ambition

The problem gives a set of wealthy individuals and a set of companies. Each person has a list of companies they are willing to buy, and each company can be assigned to at most one person.

codeforcescompetitive-programming
CF 103708F - Froginald the frog

I can’t reliably write a correct editorial for this without the actual problem statement. “Codeforces 103708F - Froginald the frog” isn’t included in your prompt, and I don’t have access to the missing input/output details or constraints.

codeforcescompetitive-programming
CF 103708E - Erudite of words

I don’t have the actual statement of Codeforces 103708E - Erudite of words in the prompt, and without it I can’t reliably reconstruct the problem or produce a correct editorial.

codeforcescompetitive-programming
CF 103708G - Going to the Regional

I can’t write a correct editorial yet because the problem statement for Codeforces 103708G - Going to the Regional is missing from your prompt.

codeforcescompetitive-programming
CF 103708D - Different Pass a Ports

The problem statement for Codeforces 103708D - Different Pass a Ports is missing from your message, so I don’t have enough information to write a correct editorial.

codeforcescompetitive-programming
CF 103708C - Candies median

I don’t have the actual statement for Codeforces 103708C - Candies median in your prompt, and without it I’d be forced to guess the task, which would make the editorial unreliable.

codeforcescompetitive-programming
CF 103708A - Anya's gifts

I don’t have the actual problem statement for Codeforces 103708A - Anya’s gifts, so I can’t safely write a correct editorial yet without risking inventing details. Please paste the full statement (or at least the input/output description and constraints).

codeforcescompetitive-programming
CF 103708B - Building 5G antennas

I don’t have the actual problem statement for Codeforces 103708B - Building 5G antennas in your prompt, so I can’t reliably reconstruct the intended solution, constraints, or even what is being optimized.

codeforcescompetitive-programming
CF 103714H - Еловый городок

The problem statement section is empty, so I don’t have enough information to reconstruct what Codeforces 103714H (“Еловый городок”) is asking.

codeforcescompetitive-programming
CF 103714I - Булочка с маком

I can’t reliably write a correct editorial for this because the actual problem statement for Codeforces 103714I - “Булочка с маком” isn’t included, and I don’t have enough information to reconstruct it from the title alone without risking a wrong solution.

codeforcescompetitive-programming
CF 103714G - Уязвимое хэширование

I’m missing the actual problem statement for Codeforces 103714G - “Уязвимое хэширование”, so I can’t reliably reconstruct the solution or write a correct editorial without guessing details.

codeforcescompetitive-programming
CF 103714F - Шахматы безумия

I can’t write a correct editorial yet because the actual problem statement for Codeforces 103714F - “Шахматы безумия” is missing from your prompt. Right now I only have the title, but no rules about the board, moves, inputs, or required output.

codeforcescompetitive-programming
CF 103714D - Ловушка

We are given a line of cows indexed from left to right. Each cow has a weight. Then we are given many independent “raids.” A raid is defined by two numbers, a starting position and a step size.

codeforcescompetitive-programming
CF 103714E - Не пили сук, на котором сидишь!

I can’t reliably reconstruct Codeforces 103714E from just the title, and the statement is missing from your prompt.

codeforcescompetitive-programming
CF 103714C - Парящие Городские Установки

The statement section is empty, so there isn’t enough information to reconstruct what Codeforces 103714C is asking for.

codeforcescompetitive-programming
CF 103714A - Диплом

The problem statement is missing from your prompt, so I can’t reconstruct a correct editorial yet. Right now I only see the title “103714A - Диплом”, but no description of what the input, output, or task actually is.

codeforcescompetitive-programming
CF 103714B - Урок геометрии

I don’t have the actual statement of Codeforces 103714B - “Урок геометрии” available in your prompt, and without it I’d be forced to guess the problem structure, which would make the editorial incorrect.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 109

Let $m=2^n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 103715F - Сократить путешествие

The problem statement section is empty, so there isn’t enough information to reconstruct what “Сократить путешествие” actually asks.

codeforcescompetitive-programming
CF 103715G - Найдите х

I can’t reliably write the editorial yet because the problem statement for Codeforces 103715G - “Найдите х” is not included in your prompt, and I also can’t uniquely reconstruct it from the title alone.

codeforcescompetitive-programming
CF 103715E - Магические зелья

I can’t write a correct editorial yet because the actual problem statement for CF 103715E - “Магические зелья” isn’t included in your prompt.

codeforcescompetitive-programming
CF 103715D - Химия

I can’t reliably write a correct editorial for this yet because the actual problem statement for Codeforces 103715D (“Химия”) isn’t included, and I shouldn’t guess the task.

codeforcescompetitive-programming
CF 103715C - Контроль сахара

We are given a list of sugar shops. Each shop has an initial price, and that price increases by exactly one coin every day. So if a shop starts at price a[i], then on day 1 it costs a[i], on day 2 it costs a[i] + 1, and so on. Every day, you go shopping with a fixed budget x.

codeforcescompetitive-programming
CF 103715B - Каракули

I can’t reliably write a correct editorial for this yet because the actual problem statement for CF 103715B - “Каракули” isn’t included in your prompt.

codeforcescompetitive-programming
CF 103715A - Домашнее задание

The statement for Codeforces 103715A - “Домашнее задание” is missing from your prompt, so I cannot safely reconstruct the problem or produce a correct editorial yet.

codeforcescompetitive-programming
CF 103719K - Фатальная ошибка

We are given a sequence of convex polygons, each representing a stain on a sheet of paper. These sheets were originally stacked in a strict nesting order: the polygon on sheet i+1 is strictly contained inside the polygon on sheet i.

codeforcescompetitive-programming
CF 103719L - AvtoBus

We are told the total number of wheels in a bus fleet. Every vehicle in the fleet is either a 4-wheel bus or a 6-wheel bus, and we are not given how many of each type exist.

codeforcescompetitive-programming
CF 103719I - Formalism for Formalism

I cannot reliably reconstruct Codeforces 103719I - Formalism for Formalism from available context, because the statement is not accessible in the prompt and the problem name corresponds to a gym problem where multiple unrelated tasks appear under similar metadata.

codeforcescompetitive-programming
CF 103719J - Rooks Defenders

I don’t have the actual statement for “Codeforces 103719J - Rooks Defenders” in your message, so I can’t reconstruct the intended model, constraints, or solution without risking hallucinating the problem.

codeforcescompetitive-programming
CF 103719H - Счастливый порядок

We are asked to generate an infinite ordered list of special integers and pick the n-th one. A number is considered special if its decimal representation consists only of the digits 4 and 7. These numbers form an infinite set like 4, 7, 44, 47, 74, 77, 444, and so on.

codeforcescompetitive-programming
CF 103719G - Спасение Минотавра

We are given an $n times m$ grid where each cell will eventually be marked either as a wall or left empty. Instead of being given the grid directly, we are given parity constraints on two families of diagonals.

codeforcescompetitive-programming
CF 103719F - Маткульт-привет!

We are given a segment of integers from $l$ to $r$, where both bounds can be as large as $10^{12}$. For every number $x$ in this segment we can compute Euler’s totient function $varphi(x)$, which counts how many integers from $1$ to $x$ are coprime with $x$.

codeforcescompetitive-programming
CF 103719D - Toss a Coin to Your Graph...

We are given a directed graph where every vertex carries a fixed positive weight. We begin by placing a coin on any vertex of our choice. Each time the coin is placed on a vertex, we record that vertex’s weight in a log.

codeforcescompetitive-programming
CF 103719B - Шахматы и пути

We are given a very large rectangular chessboard where each cell is either white or black in the standard checkerboard pattern determined by coordinate parity.

codeforcescompetitive-programming
CF 103719E - Typical Party in Dorm

I’m missing the actual problem statement for Codeforces 103719E - Typical Party in Dorm (the “Input / Output / Description” parts are empty in your message).

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 108

Work over the alphabet ${0,1,\dots,9}$, interpreted as decimal digits, and use Knuth’s notion of m-ary primes and preprimes from Algorithm F in Section 7.

taocpmathematicsalgorithmsvolume-4math-hard
CF 103719C - Меховые подпоследовательности

We are given an array of length n, and we look at subsequences defined by choosing any increasing sequence of indices. For each chosen subsequence, we take the multiset of values and compute its mex, the smallest nonnegative integer that does not appear in it.

codeforcescompetitive-programming
CF 103719A - Stone Age Problem

We are maintaining a long row of stones, each stone holding a numeric value. Initially, every position starts from a fixed baseline, typically zero. After that, a sequence of operations is applied.

codeforcescompetitive-programming
CF 103720G - Множество с запросами

We maintain a dynamic set of positive integers. The set starts empty, and we process three kinds of operations: inserting a new number, deleting an existing number, and answering a query about a combinational score defined over all subsets of the current set.

codeforcescompetitive-programming
CF 103720F - База отдыха

We are managing a line of N numbered cottages, initially all empty. Over time, we receive two types of commands: booking requests and cancellations.

codeforcescompetitive-programming
CF 103720D - День рождения

We are given three piles of candies. Two of the piles are guaranteed to start with the same size, while the third may differ. Two players alternate turns.

codeforcescompetitive-programming
CF 103720E - Максимизируй AND

Let $f$ be a Boolean function of variables $x1,dots,xn$ and let $g$ be obtained from $f$ by the condensation $x{k+1} leftarrow xk$. Thus $g$ is the restriction of $f$ to the diagonal substitution in which every occurrence of $x{k+1}$ is replaced by $xk$.

codeforcescompetitive-programming
CF 103720C - Неправильная яблоня

We are given three sorted sequences of positive integers. Each sequence represents the heights of saplings loaded in a separate truck, and within each truck the saplings are already sorted in non-decreasing order.

codeforcescompetitive-programming
CF 103720A - Диагональный прямоугольник

Let $f$ be a Boolean function of variables $x1,dots,xn$ and let $g$ be obtained from $f$ by the condensation $x{k+1} leftarrow xk$. Thus $g$ is the restriction of $f$ to the diagonal substitution in which every occurrence of $x{k+1}$ is replaced by $xk$.

codeforcescompetitive-programming
CF 103720B - Мëд для Михаила

The problem statement section is empty, so there isn’t enough information to reconstruct what Codeforces 103720B (“Мëд для Михаила”) is asking.

codeforcescompetitive-programming
CF 103729H - Hamster and Multiplication

Let $f$ be a Boolean function of variables $x1,dots,xn$ and let $g$ be obtained from $f$ by the condensation $x{k+1} leftarrow xk$. Thus $g$ is the restriction of $f$ to the diagonal substitution in which every occurrence of $x{k+1}$ is replaced by $xk$.

codeforcescompetitive-programming
CF 103729M - Super Star Spectacle

I don’t have the actual problem statement for Codeforces 103729M - Super Star Spectacle, so I can’t reliably reconstruct the intended solution, constraints, or edge cases.

codeforcescompetitive-programming
CF 103729L - Chtholly and the Broken Chronograph

I can’t reliably write a correct editorial yet because the problem statement for Codeforces 103729L - Chtholly and the Broken Chronograph is not available in your prompt, and it is not fully accessible from the search results (they only show submission/status logs, not the…

codeforcescompetitive-programming
CF 103729K - PTT

I can’t produce a correct editorial yet because the actual problem statement for Codeforces 103729K - PTT is not included in your message. Right now there’s no information about: what the input represents, what is being optimized or computed, or even the output format.

codeforcescompetitive-programming
CF 103729I - Latitude Compressor

I can’t reliably write a correct editorial without the actual problem statement. “Latitude Compressor” isn’t enough to reconstruct the task, and guessing would almost certainly produce the wrong solution details, constraints, and even the wrong algorithm.

codeforcescompetitive-programming
CF 103729J - Palindrome Reversion

I don’t have the actual statement for Codeforces 103729J - Palindrome Reversion in the prompt, and without it I can’t reliably reconstruct the intended problem or derive a correct solution.

codeforcescompetitive-programming
CF 103729D - Transition

We are given two binary strings of equal length. The task is to transform the first string into the second using two allowed operations. One operation swaps any two positions at a cost equal to the distance between those indices.

codeforcescompetitive-programming
CF 103729G - Brick

I don’t have the actual statement for Codeforces 103729G - Brick in your message, so I can’t safely write a correct editorial without risking inventing details.

codeforcescompetitive-programming
CF 103729B - Potion(easy version)

Let $g$ be obtained from $f$ by setting $x{k+1} leftarrow xk$. Every subfunction of $g$ is obtained by fixing variables among $x1,dots,xk,x{k+2},dots,xn$, and then evaluating $f$ under the additional constraint $x{k+1}=xk$.

codeforcescompetitive-programming
CF 103729F - Angel

We are given a line of $n$ holes labeled from left to right. An entity starts in one of these holes, but its exact starting position is unknown. Every minute, before we act, we are allowed to inspect exactly one hole.

codeforcescompetitive-programming
CF 103729E - Multigate

I can write the full editorial in that format, but I’m missing the actual problem statement for Codeforces 103729E - Multigate.

codeforcescompetitive-programming
CF 103729C - Potion(hard version)

I can’t reliably write a correct editorial for “Codeforces 103729C - Potion (hard version)” without the actual problem statement.

codeforcescompetitive-programming
CF 103729A - Nucleic Acid Test

I don’t have the actual statement for Codeforces 103729A “Nucleic Acid Test” in the prompt you provided, so I can’t safely reconstruct the intended problem or derive a correct solution without guessing.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 107

A string is written over a totally ordered infinite alphabet.

taocpmathematicsalgorithmsvolume-4hm-hard
CF 103736K - Klee's Wonderful Adventure

We are given a set of points on a 2D plane. Each point is a node, and Klee can move directly between any pair of points. The cost of moving depends only on which quadrants the two endpoints lie in.

codeforcescompetitive-programming
CF 103736G - Ganyu Segment Tree

Let $f(x1,dots,xn)$ be a Boolean function, and let $G(z)$ be its generating function in the sense of Exercise 25, so that $$G(z)=sum{xin{0,1}^n} f(x), z^{w(x)},$$ where $w(x)=x1+cdots+xn$ is the Hamming weight of $x$.

codeforcescompetitive-programming
CF 103736J - IHI's Magic String

We are maintaining a string that starts empty and is modified by a sequence of operations. Each operation either appends a lowercase character to the end, removes the last character if one exists, or performs a global substitution that replaces every occurrence of a given…

codeforcescompetitive-programming