brain

tamnd's digital brain — notes, problems, research

41641 notes

TAOCP 1.2.10 Exercise 12

Let F(t)=G(e^t)=\sum_{k\ge 0} p_k e^{kt}.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 1.2.10 Exercise 14

Let $G_n(z) = (q + pz)^n$ be the generating function of the binomial distribution, where $p+q=1$, $q=1-p$, $0<p<1$.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 1.2.10 Exercise 13

Let G_n(z)=\prod_{k=2}^{n}\frac{z+k-1}{k} be the probability generating function in Eq.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 1.2.10 Exercise 10

Let $X[1],\ldots,X[n]$ be independent uniform draws from a set of $M$ objects.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.2.10 Exercise 9

Let $X[1],X[2],\ldots,X[n]$ be chosen independently from a set of $M$ distinct elements, each of the $M^n$ sequences being equally likely.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.2.10 Exercise 8

Let the sample space consist of all sequences $(X[1],X[2],\ldots,X[n])$ with each $X[k]$ chosen independently from a set of $M$ distinct elements.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.2.10 Exercise 6

Let $G(z)=\sum_k p_k z^k$ be a probability generating function with $G(1)=1$.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 1.2.10 Exercise 4

Let $X_1,\ldots,X_n$ be independent trials with $\Pr(X_i=\text{head})=p$ and $\Pr(X_i=\text{tail})=q=1-p$.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 1.2.10 Exercise 7

Let $X[1],X[2],\ldots,X[n]$ be a random sequence containing exactly $m$ distinct values.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.2.10 Exercise 5

The distribution in Fig.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 1.2.10 Exercise 1

From (4) with $k=0$, p_{n0}=\frac{1}{n}p_{n-1,-1}+\frac{n-1}{n}p_{n-1,0}.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.2.1 Exercise 15

Let $\prec$ be a relation on a set $S$ satisfying properties (i)–(iii) of the exercise, so that $S$ is well-ordered by $\prec$.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 1.2.10 Exercise 2

Let G(z)=\sum_{k} p_k z^k, \qquad G(1)=\sum_k p_k=1.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 1.2.10 Exercise 3

For Algorithm M, the number of times step M4 is executed is the random variable $A$, whose distribution satisfies the results of Section 1.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 1.2.1 Exercise 13

Let the original Algorithm E be augmented so that at the beginning of every execution of each step E1, E2, E3, and E4, the operation $T \leftarrow T + 1$ is performed, with $T = 0$ initially.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.2.1 Exercise 12

The solution must be rebuilt because the central issue is not a norm estimate but the fact that the _text’s intended generalization of Algorithm E is not a Euclidean algorithm in_ $\mathbb{Z}[\sqrt{2}...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.2.1 Exercise 14

A correct solution must avoid any assumption that Floyd verification conditions are decidable by semantic truth tables.

taocpmathematicsalgorithmsvolume-1research
TAOCP 1.2.1 Exercise 11

The previous solution failed because the proposed identity was incorrect.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.2.1 Exercise 10

We prove by induction on integers $n \ge 10$ that 2^n > n^3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.2.1 Exercise 8

Let $P(n)$ denote the statement that n^3 = (n^2 - n + 1) + (n^2 - n + 3) + \cdots + (n^2 + n - 1).

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.2.1 Exercise 9

Let $P(n)$ be the statement $(1 - a)^n \ge 1 - na$ for a fixed real number $a$ satisfying $0 < a < 1$, and for all positive integers $n$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.2.1 Exercise 5

Let $P(n)$ denote the statement that every integer $n>1$ can be written as a product of one or more prime numbers, where a prime number is considered a product consisting of itself alone.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.2.1 Exercise 4

Let $P(n)$ denote the statement $F_n \ge \phi^{,n-2}$ for all positive integers $n$, where $F_0 = 0$, $F_1 = 1$, $F_{n+1} = F_n + F_{n-1}$, and $\phi = (1 + \sqrt{5})/2$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.2.1 Exercise 6

Before step E4, equations (6) state that $a' m + b' n = c,$ $a m + b n = d.$ Step E2 supplies integers $q$ and $r$ such that $c = qd + r.$ After step E4, the updated variables are

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.2.1 Exercise 7

Let $S_n = n^2 - (n-1)^2 + (n-2)^2 - \cdots + (-1)^{n-1} 1^2$ for positive integers $n$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.1 Exercise 9

Let $C_1=(Q_1,I_1,\Omega_1,f_1)$ and $C_2=(Q_2,I_2,\Omega_2,f_2)$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.2.1 Exercise 2

The argument attempts a strong induction proof of the statement $P(n): a^{\,n-1}=1$ for all positive integers $n$, with $a>0$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.2.1 Exercise 3

Let S_n = \frac{1}{1 \times 2} + \frac{1}{2 \times 3} + \cdots + \frac{1}{(n - 1)n}.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.2.1 Exercise 1

To extend induction from positive integers to nonnegative integers, the starting point is shifted from $1$ to $0$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.1 Exercise 6

Let $T_5$ denote the average number of executions of step E1 of Algorithm E when the second input is fixed as $n=5$ and the first input $m$ ranges uniformly over the integers $1,2,3,4,5$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.1 Exercise 5

An algorithm in the sense of Section 1.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.1 Exercise 7

Let $m$ be fixed and let $f(m,n)$ denote the number of executions of step E1 of Algorithm E starting from input $(m,n)$, $n\ge 1$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.1 Exercise 8

The flaw in the previous solution is not merely a mistake in the proof, but an incorrect encoding of Euclid’s subtraction step.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.1 Exercise 2

Let the variables $m$ and $n$ at the beginning of a general execution of step E1 be those currently held by Algorithm E.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.1 Exercise 3

A replacement operation of the form $x \leftarrow y$ is trivial when it merely copies a value without participating in any further computation inside that step.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.1 Exercise 4

Apply Algorithm E to the integers $m = 6099$ and $n = 2166$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.1 Exercise 1

Let the initial values be $a_0, b_0, c_0, d_0$ and the final required configuration be $a = b_0$, $b = c_0$, $c = d_0$, $d = a_0$.

taocpmathematicsalgorithmsvolume-1simple
IMO 1967 Problem 4

Let a triangle $ABC$ be required to be similar to a fixed acute triangle $A_1B_1C_1$ with correspondence $A \leftrightarrow A_1$, $B \leftrightarrow B_1$, $C \leftrightarrow C_1$, and suppose that the…

imomathematicsolympiad
CF 105346A - Spookeepy

We are given a fixed point on a 2D grid representing where we currently stand inside a mansion. Along with it, we are given a list of other points scattered across the plane. The task is to identify which of these points is closest to our position using Euclidean distance.

codeforcescompetitive-programming
CF 105346G - Pumpkin Patch

We are given a grid where each cell behaves like a terrain type in a small maze. The traveler starts from exactly one cell marked S and must reach a unique exit cell marked E. Movement is allowed in the four cardinal directions, and each move costs one unit of time.

codeforcescompetitive-programming
CF 105346F - Haunted House

We are given a building modeled as an undirected graph where rooms are nodes and doors are edges. Harry starts in a specific room and wants to reach any of several exit rooms. At the same time, there are multiple ghosts placed in fixed rooms.

codeforcescompetitive-programming
CF 105346E - Candy Eating

We are given several types of candy. Each type has a fixed number of pieces available and a fixed tastiness per piece.

codeforcescompetitive-programming
CF 105346D - Nightmare on 24th

We are given a row of buildings indexed from left to right, where each building contains a certain number of students. Freddy always starts from the first building and can only move forward in order.

codeforcescompetitive-programming
CF 105346B - Ternary Nightmare

We are given a sequence of characters consisting only of 0, 1, and 2. We want to choose a contiguous segment of this sequence such that within that segment, the number of 2 characters does not exceed a given limit k.

codeforcescompetitive-programming
IMO 1967 Problem 3

The expression factorises as

imomathematicsolympiad
CF 105345C - Spooky Hallway

We are given a binary string representing a row of lanterns, where each position is either 0 or 1. In a single operation, we choose any contiguous segment and flip every bit inside it, turning 0 into 1 and 1 into 0.

codeforcescompetitive-programming
CF 105345I - Trick or Treat

We are given a line of houses arranged in a row. Each house has a deadline, measured in minutes from the start, after which Alice can still reach it but will not receive candy if she arrives exactly at that time or later.

codeforcescompetitive-programming
CF 105345G - Pumpkin Patch

The maze is a small grid where each cell behaves like a terrain type that affects how Sam can move. Some cells are freely passable, some are blocked, and some impose a resource constraint: Sam may need to collect candy corns to pass through certain obstacles.

codeforcescompetitive-programming
CF 105345H - Speedway Evacuation

We are given a line segment of integer positions from 0 to n. Several students initially occupy positions between 1 and n−1. Each student independently chooses a direction, left toward 0 or right toward n, each with probability 1/2.

codeforcescompetitive-programming
CF 105345F - Haunted House

The task is to determine which exit rooms in a building are safe for Harry to reach given that ghosts are also moving through the same building at the same speed. We can view the house as an undirected graph where rooms are nodes and doors are edges.

codeforcescompetitive-programming
CF 105345E - Candy Eating

We are given several types of candy, where each type has a limited supply and a fixed tastiness per piece. Charlie can eat candy over a limited number of days, but each day comes with two constraints: he cannot exceed a fixed number of candies per day, and he is not allowed to…

codeforcescompetitive-programming
CF 105336L - 网络预选赛

We are given a grid of lowercase letters with $n$ rows and $m$ columns. From this grid, we are interested in selecting any two consecutive rows and any two consecutive columns. Each such choice defines a $2 times 2$ submatrix.

codeforcescompetitive-programming
CF 105336K - 取沙子游戏

There is a pile of $n$ stones and two players who alternate turns, with Alice moving first. On each move a player removes some positive number of stones from the pile. The size of a move is restricted in two ways.

codeforcescompetitive-programming
CF 105336J - 找最小

We are given two binary-like sequences of equal length. Each position contains a 31-bit non-negative integer, and at every index we are allowed to swap the two values in that position any number of times. After performing swaps, we end up with two new sequences.

codeforcescompetitive-programming
CF 105336I - 找行李

We are given two sets of points on a number line. One set represents luggage items, each sitting at some integer position. The other set represents people standing in front of a conveyor belt, also at integer positions.

codeforcescompetitive-programming
CF 105336H - 另一个游戏

We are given a turn-based game with a single evolving state: a combat strength value and a cumulative damage value. Initially the strength is some fixed value $a0$, and damage starts at zero. There are $n$ rounds, and in each round we must choose exactly one of two actions.

codeforcescompetitive-programming
IMO 1967 Problem 2

Let $AB$ be the unique edge of the tetrahedron exceeding $1$, while all other edges do not exceed $1$.

imomathematicsolympiad
CF 105336G - 疯狂星期六

A group of n people goes to a restaurant, and each person has a personal spending limit. This limit already includes the cost of transportation to the restaurant, and any additional spending inside the restaurant must keep their total expenditure within their limit.

codeforcescompetitive-programming
CF 105336F - 包子鸡蛋 III

We are given a random string of length $n$, built independently character by character from the lowercase alphabet. Each position is assigned letter $i$ with probability $pi$.

codeforcescompetitive-programming
CF 105336E - 随机过程

We are generating $n$ independent random strings, each of length $m$, where every character is chosen uniformly from the 26 lowercase English letters.

codeforcescompetitive-programming
CF 105336B - 军训 II

We are given a list of heights and are allowed to reorder them arbitrarily into a line. For any fixed arrangement, every contiguous segment contributes a cost equal to the difference between the tallest and the shortest person inside that segment.

codeforcescompetitive-programming
CF 105336A - 军训 I

We are given an $n times m$ grid of students standing in a rectangle. Each cell either contains a student or is empty. From this initial configuration, an operation is applied repeatedly, where each operation “compresses” the arrangement according to one of four commands.

codeforcescompetitive-programming
CF 105336D - 编码器-解码器

We are given a string $S$ of length $n$. From this string, a second much larger string is constructed recursively.

codeforcescompetitive-programming
IMO 1967 Problem 1

The quantity to be maximized is the distance to the nearest vertex among $A,B,C,D$ over the parallelogram.

imomathematicsolympiad
CF 105317L - Minimum Enclosing Rectangle

We are given a collection of points on a 2D plane, and we want to enclose all of them inside a rectangle whose sides are aligned with the coordinate axes. Among all such axis-aligned rectangles, we are asked to find the one with the smallest possible area.

codeforcescompetitive-programming
CF 105317K - Pèppito.

We are given a tree with a value written on every node. Each query picks two nodes, defining a unique simple path between them. Along that path we look at the sequence of node values and count how many times each value appears.

codeforcescompetitive-programming
CF 105317I - Split the Stri ng

We are given a single string and we are allowed to choose exactly one cut position that splits it into a left part and a right part. For each cut, we look at the two resulting strings and ask whether each one can be rearranged into a palindrome.

codeforcescompetitive-programming
CF 105317J - JSUM

We are given a static array of integers, and we are asked to look at every contiguous subarray. For each subarray, we compute the greatest common divisor of all elements inside it, and then we sum all of those gcd values across all subarrays.

codeforcescompetitive-programming
CF 105317E - Eduardo Looking for Juan (Hard Version)

We are given a tree with $n$ nodes, where each node has a small integer value $ai$. Each query selects two nodes $u$ and $v$, and we consider the unique simple path between them.

codeforcescompetitive-programming
CF 105317H - Juan vs. Man

We are asked to construct an array of length $n$, where every element lies between $1$ and $m$, with a global restriction on its subarrays.

codeforcescompetitive-programming
CF 105317G - Carlo's Password

Each input string in the list can be thought of as a very short sequence of characters, at most length six. For every query string, we are asked whether it can be formed by deleting some characters from at least one of these stored strings without changing the order of the…

codeforcescompetitive-programming
CF 105317D - Eduardo Looking for Juan (Easy Version)

We are given a tree with up to a very large number of nodes, where each node has a small integer value between 1 and 70. Each query gives two nodes, and we look at the unique simple path between them. Along this path, we multiply all node values together.

codeforcescompetitive-programming
CF 105317C - K Flips

We are working with a binary string that represents a line of tables, where each position is either flipped or not flipped. The string changes only through direct point updates: a query of type 1 toggles a single position from 0 to 1 or from 1 to 0.

codeforcescompetitive-programming
CF 105317A - Juan and Alfino

We are given two integers. One represents the cost of a single sandwich, and the other represents how much money Juan has available. Juan wants to spend his money only on full sandwiches and give them to friends, where each friend receives exactly one sandwich.

codeforcescompetitive-programming
CF 105316L - BBS Queries

We are given a balanced parentheses sequence of length $2n$. Every position in this sequence is a bracket, and every opening bracket is matched with exactly one closing bracket, forming a tree-like nesting structure.

codeforcescompetitive-programming
CF 105316M - ACPC

We are given a single short string representing a friend’s name. Regardless of what this string is, we must always output the same fixed word.

codeforcescompetitive-programming
CF 105316J - Epic Fight

We are given a line of $n$ cells connected like a simple path, so from any cell $i$ you can move only to $i-1$ or $i+1$ if those exist. A token starts on a chosen cell, and that cell is immediately marked as visited. Two players alternate moves, starting with Ahmad.

codeforcescompetitive-programming
CF 105316H - One Punch MEX

We start with a collection of stones labeled from 1 to n. All stones are present initially. Then a random process runs for exactly n steps. At each step, one of the remaining stones is chosen uniformly at random and removed permanently.

codeforcescompetitive-programming
CF 105316I - Nested Circles

We are given several circles on a 2D integer grid, each defined by a center point and a radius. After reading all circles, we receive a sequence of query points. For each query point, we must count how many of the given circles contain or touch that point.

codeforcescompetitive-programming
CF 105316F - Legend Whispers

We are given two arrays of the same length. The second array is fixed, but the first array can be permuted arbitrarily. After choosing a permutation of the first array, each position pairs one value from the first array with one value from the second array.

codeforcescompetitive-programming
CF 105316E - Zero Hour

We are given several independent test cases. In each test case, we receive a list of integer values, where each value represents the power of a soldier.

codeforcescompetitive-programming
CF 105316A - Rajaee in the Kitchen

We are given an array of positive integers. The task is to split it into several consecutive non-empty segments. Each element must belong to exactly one segment, so every valid solution corresponds to a full partition of the array into contiguous blocks.

codeforcescompetitive-programming
CF 105316C - Hungry Horse

We are given several independent scenarios where a horse starts at position 0 and moves only in the positive direction along a line. Along this line there are food dishes placed at distinct positions. Each dish requires some fixed amount of time to eat once the horse reaches it.

codeforcescompetitive-programming
CF 105315L - Monther's Birthday

We are given multiple independent test cases. Each test case consists of several pairs of integers. For each pair $(a, b)$, we compute a value defined as $a^b$.

codeforcescompetitive-programming
CF 105315K - Ka3bool's Birthday

We are maintaining a dynamic set of integers where elements are inserted and deleted one operation at a time. After every update, we need to compute how “fragmented” the set is when viewed on the number line.

codeforcescompetitive-programming
CF 105315I - Zain's Birthday

We are given a row of tiles numbered from 0 up to n, and a cat starts at tile 0. From any tile i, the cat can jump forward to any tile j as long as j is strictly ahead and does not exceed k steps away, meaning 1 ≤ j − i ≤ k.

codeforcescompetitive-programming
CF 105315H - Abdulrahman's Birthday

We are given a collection of items, each item has two values, a and b. From these items we must choose exactly k distinct indices i1 < i2 < ... < ik. The score of a chosen sequence is the sum of the selected a-values minus the maximum b-value among the selected elements.

codeforcescompetitive-programming
CF 105315G - Nagham's Birthday

We are given a directed or undirected weighted graph for each test case, together with a designated start node and a target node.

codeforcescompetitive-programming
CF 105315E - Rama's Birthday

We are given a sequence that describes cumulative gcd information of another hidden array. For each position $i$, the value $bi$ equals the gcd of the first $i$ elements of an unknown array $a$.

codeforcescompetitive-programming
IMO 1966 Problem 6

Take triangle $ABC$ and choose coordinates so that area ratios can be computed explicitly without relying on any assumed affine factorization.

imomathematicsolympiad
CF 105315A - Marble's Birthday

We are given several directed graphs, each described by nodes and directed edges. A directed edge from one node to another means you can travel only in that direction.

codeforcescompetitive-programming
CF 105315D - Manar's Birthday

We are given several independent test cases. In each test case, there is a list of strings, and we want to count ordered pairs of distinct indices such that when we concatenate the first string with the second, the resulting string reads the same forward and backward.

codeforcescompetitive-programming
CF 105315C - Iyaad's Birthday

We are given several independent experiments. In each experiment, there is a reference integer $D$ that represents the DNA of a specific cat, and a list of other cats represented by integers $ai$. Each integer encodes genetic traits as bits.

codeforcescompetitive-programming
CF 105314K - Ahmad and Distinct Syndrome

We are given several independent test cases. In each test case, we are shown a line of contestants, each carrying a balloon of some color represented by an integer.

codeforcescompetitive-programming
CF 105314H - Hamza and the Forgotten Tree Syndrome

We are given a tree where each node carries an integer value. For every unordered pair of nodes $u, v$, we look at the unique simple path between them. On that path we define two quantities: the number of nodes on the path, and the gcd of all node values along the path.

codeforcescompetitive-programming
CF 105314J - Ahmad and Prediction Syndrome

The task describes a very simple qualification rule for a contest. Each test case gives a single integer representing how many distinct balloons a team has robbed. A team qualifies if and only if it has robbed at least 8 different balloons.

codeforcescompetitive-programming
CF 105314E - Ahmad and Substrings Syndrome

We are given a base string s. For each query, we are also given another string t, but the twist is that t is not fixed in order. We are allowed to permute its characters arbitrarily, and we want to know whether some substring of s can be rearranged to match t.

codeforcescompetitive-programming
CF 105314G - Ahmad and Cinema Syndrome

We are given several independent scenarios. In each scenario, there are $n$ movies, each with a fixed ticket price. The goal is to watch all movies exactly once. Normally, watching a movie requires paying its individual ticket cost.

codeforcescompetitive-programming
CF 105314C - Hamza and Fulfillment Syndrome

We are given several test cases. Each test case describes a sequence of items arranged in a fixed order. Every item has an ID and a color. From this sequence, we want to select a subsequence of items while preserving the original order.

codeforcescompetitive-programming
CF 105314D - The Boys and Wasting Time Syndrome

We are given several test cases. In each test case there is an array of items. Each item has two attributes: a value a[i] and a weight-like parameter b[i].

codeforcescompetitive-programming