brain
tamnd's digital brain — notes, problems, research
43815 notes
**Exercise 3.
Let m=9999999999=10^{10}-1.
Let $m$ be a positive integer modulus.
Let aX=qw+r,\qquad 0\le r<w.
Let $m$ be a positive integer modulus and let $a, c, X_0$ be integers with $0 \le X_0 < m$.
The flawed solution attempts to describe specific factorizations, but the actual question is to identify structural patterns visible in the table of factorizations of numbers of the form $w \pm 1$, wh...
We are asked to discuss the calculation of linear congruential sequences with modulus $m = 2^{32}$ on two's-complement machines such as the IBM System/370 series.
Let $m$ be a positive integer less than the computer word size $w$, and let $x$ and $y$ be nonnegative integers satisfying $0 \le x, y < m$.
We are asked to compute (aX + c) \bmod w in MIX using **three instructions** when $m = w$ and $\gcd(a,w)=1$, with the result ending in register X.
Let $w$ be the word size, $0 \le a,x < m < w$, and $\gcd(m,w)=1$.
Let $w$ be the word size and let $X$ be stored in location $\texttt{XRAND}$.
Equation (2) defines the linear congruential sequence by X_{n+1}\equiv aX_n+c \pmod m.
Equation (6) asserts that, for $k \ge 0$, $X_{n+k} = \bigl(a^k X_n + (a^k - 1)c/b\bigr) \bmod m, \qquad b = a-1. \eqno(6)$ We seek an expression for $X_{n+k}$ when $k < 0$.
If $a$ and $m$ are not relatively prime, there exists a nontrivial common factor $d > 1$ such that $d \mid a$ and $d \mid m$.
Assume that $(a,m)=1$.
A linear congruential sequence has the form X_{n+1} \equiv aX_n + c \pmod m.
**Exercise 3.
Let $f$ be an arbitrary function from ${0,1,\ldots,m-1}$ into itself.
Let K(X) denote one application of Algorithm K.
Let $N=m^k$.
**Exercise 3.
**Solution.
**Exercise 3.
**Exercise 3.
**Solution to Exercise 3.
Let $L_m$ denote the length of the longest cycle in the functional digraph of a random mapping $f$ on an $m$-element set.
Let the trajectory be X_0,\;X_1=f(X_0),\;X_2=f(X_1),\ldots and let the eventual cycle have length $\lambda$.
Let a number in the middle-square method have $2n$ digits in base $b$, and let $X_k$ denote the $k$th number in the sequence.
Let X_{n+1}=f(X_n),\qquad X_n\in\{1,\ldots,m\}, where $f$ is chosen uniformly from the $m^m$ mappings of $\{1,\ldots,m\}$ into itself, and $X_0$ is chosen uniformly from the $m$ possible starting valu...
**Exercise 3.
Let X_0,X_1,X_2,\ldots be a sequence generated by
**Exercise 3.
Algorithm K generates each new value of $X$ by a fixed deterministic rule applied to the preceding value.
The sequence takes its values from the finite set \{0,1,\ldots,m-1\}, which contains exactly $m$ elements.
Step K11 is \text{K11.
In the middle-square method for $10$-digit numbers, we square the current value and take the middle $10$ digits of the resulting $20$-digit number.
Let $X_i$ denote the number of occurrences of digit $i$ in a random sequence of $1{,}000{,}000$ decimal digits.
The desired outcome is a digit distributed as uniformly as possible on the set ${0,1,\ldots,9}$.
Each input item is a permutation of a finite length, and you are allowed to cyclically rotate it. A rotation means taking the last element and moving it to the front, repeated any number of times.
We are given a tree with $N$ nodes, and each node carries a single uppercase letter. The structure of the tree is fixed, but we are allowed to choose any node $u$ as a root. Once rooted, every node defines a rooted subtree consisting of itself and all nodes below it.
We are given a process that starts at position 0 and evolves for $T$ steps. At every second, we either increase the position by 1 or decrease it by 1. The sequence of positions over time forms a walk on the integers, starting at 0.
Two players are playing a turn-based game that changes a single integer, the current number of spaghetti strands in a shared pile. The game always starts from zero. Lario moves first, then Muigi, and they alternate for up to 100 moves each.
We are given a square chess board of size $N times N$. Each cell is identified by integer coordinates, and a single knight piece starts on one cell while a target cell is fixed elsewhere on the board.
We are given an even number of permutations, all of the same length. Each permutation represents a cyclic object: we are allowed to rotate it any number of times, meaning we can choose any cyclic shift of its elements.
We are given a collection of noodle strands, each carrying a numeric flavor value. We need to divide these strands into several dishes. Every dish must contain at least $K$ strands, and the value of a dish is defined as the maximum flavor among the strands placed into it.
We are given a building footprint in the plane, described as an axis-aligned simple polygon. Above every point inside this footprint there is a piecewise linear roof surface.
We are given an undirected graph representing islands and direct influence paths between some pairs of islands. Influence is transitive, meaning if island A can influence B and B can influence C, then A and C are in the same connected environment even without a direct edge.
Codeforces 104666L: The Bugs
We are given two strings of equal length over the alphabet {A, C, G, T}. The second string is a permutation of the first, meaning both contain exactly the same multiset of characters.
We are asked to count how many sequences of length $N$ can be formed from an alphabet of 26 symbols, while avoiding a set of forbidden substrings.
Each musician can be viewed as a 30-bit mask describing availability across the days of November. For a given day, the corresponding bit is set if the musician is available on that day, and unset otherwise.
We are looking at all integers in a range from $N$ to $M$. For each integer $x$ in this range, we define its “variability” as the number of ways to split $x$ identical items into a convoy of identical lorries such that every lorry carries the same number of items and all…
We are given a straight pier in the plane, defined by a line passing through the origin and a second point $(A, B)$. We are allowed to choose any point on this infinite line as the location of a barbecue grill.
The game is played on a large rectangular grid that behaves like a chocolate bar. Some cells are contaminated. The two players repeatedly cut the current remaining rectangle along grid lines and discard one side of the cut, keeping the other side as the new active region.
We are given a sequence of positive integers and we consider every contiguous subarray. For each subarray, two values are extracted: the greatest common divisor of all elements inside it and the maximum element inside it.
We are given a connected structure of $N$ labeled nodes, where each pair in the input describes an undirected link between two nodes. This structure is guaranteed to be a tree, so it has exactly $N-1$ edges and no cycles.
We are given a sequence of colored bungalows arranged in a straight line from the lake toward the forest. Each bungalow contributes one character to a string, so the whole street is represented as a string where position 1 is closest to the lake and position N is at the forest…
We are given several independent piles of stones. Two players alternate turns, starting with Petyr. On each turn, the active player chooses exactly one pile and removes between one stone and a player-specific maximum: Petyr can take at most A stones, while Varys can take at…
We are given a rectangular board and a single chess-like piece placed on one cell. The piece is described by its type, such as K, Q, or R.
We are counting geometric shapes that are rectangular boxes with integer side lengths. Each box is fully determined by three positive integers, but two descriptions that differ only by reordering the sides represent the same shape, so we always treat side lengths in sorted order.
The grid represents a country split into small cells. One cell contains the king’s palace, several cells contain cities that must be visited, and every other cell is just farmland. We are allowed to build helipads on some cells.
We are given a rectangular grid of characters. A “trinity” is formed by first choosing any square subregion of this grid and then selecting all cells inside that square that lie on or strictly on one side of a diagonal of the square.
The battlefield is a rectangular grid where rows are small in number but columns are very large. Each grid
We are given a set of points in the plane, each point representing a slot machine with a profit ranking implicitly given by input order. The casino manager builds a network of straight corridors between some pairs of machines following a two-phase geometric construction.
We are given a tree described by its edges on labels from 0 to N−1, and also given N distinct points in the plane, one for each label. The task is to “draw” this tree by connecting points with straight line segments so that the resulting drawing has no crossing edges.
We are simulating a 1D pursuit with a vertical constraint. A frisbee is thrown after some initial delay. From that moment, it moves horizontally at constant speed while simultaneously falling under gravity, starting from a given height.
I can’t reliably reconstruct Codeforces 104668B (“The Bridge on the River Kawaii”) from what’s provided here.
We are given a line of cells, each cell either initially containing rabbits or being empty. In each operation we are allowed to choose a positive integer shift $K$, and then all cells act in parallel.
We are given a target string made only of lowercase letters and a multiset of available “words” from newspapers. Each word can be used any number of times, and every time we use it we effectively “cover” a contiguous substring of the target.
We are given a consecutive segment of integers starting at a and containing b numbers. So the set is a simple interval: a, a+1, ..., a+b-1. We must split this set into two nonempty groups, and then compute the sum of each group.
The tree gives us a hierarchy of nodes where each node owns a value between 1 and N. For every node, we look at the nodes in its subtree and ask a structural question about the values stored there: whether those values form exactly a permutation of consecutive integers…
A perfect parity pattern of width $n$ is equivalent to a solution of the linear constraints from Section 7.
We are given a single string that is known to come from a Caesar-style letter shift applied to some original text. In such a transformation, every character in the original string is moved forward in the alphabet by a fixed number of positions, wrapping around from z back to a.
We are given a 4 by 4 board from a simplified 2048 game. Each cell contains either zero or a power-of-two tile. A zero means the cell is empty. The board evolves by applying moves, but unlike the original game, no new tiles ever appear.
A tree is given with nodes numbered from 1 to N, rooted at node 1. Each node carries a distinct label, and these labels form a permutation of the numbers from 1 to N. For every node, we look at the nodes inside its rooted subtree and collect their labels.
Let $G = ({0,1}^n,\oplus)$ be the additive group of bit vectors of length $n$.
We are dealing with two agents on an infinite 2D grid. One agent, Keys, moves every second by exactly one grid step in one of the four cardinal directions. After moving, Keys leaves a permanent “poster” on the cell he just left.
We are given a square cake of side length $N$. The cake is cut from left to right using a sequence of heights defined by a permutation of the integers from $0$ to $N$.
We are given a group of students, each with a GPA value between 0 and 5. A student is considered “safe” only if their GPA reaches at least 2.8 after possible improvement.
The flawed argument fails because it tries to reason at the level of individual bits while treating multiplication as if it were linearly decomposable.
We are given a non-negative integer and asked to reinterpret it through a transformation on its binary representation. The process is straightforward in description but slightly indirect in execution.
We are given a binary string and we are allowed to pick any contiguous segment and reverse it in one move. After performing several such reversals, we want the string to end up in a form where all zeros appear before all ones.
We are given a single number $n$, and we must output a permutation of the integers from $1$ to $n$. For each position $i$, we compute a value formed by multiplying the index and the value placed there, namely $i cdot pi$.
The task is purely about formatting output. We are given a single string representing a name, and we must print it exactly as it appears, followed by a fixed ASCII drawing of a turtle. The drawing does not depend on the input at all, only the first line changes.
The failure in the proposed solution is not a technical detail.
We are given a 2-row grid stretched over a very long road with $m$ columns. Each column represents a meter, and at each column there are up to two values: a beauty value for running in the forward direction (top row) and a beauty value for running in the backward direction…
Each input line describes a pair of periodic events. For a given pair, two species reappear every fixed number of years, and we are told the last year when both of them appeared together. From that information we want to predict when that same pair will next appear together.
We are given a small fixed universe of knot identifiers, numbered from 1 to 1000. Sonja was assigned a list of exactly n distinct knots that she must learn.
Two people start at two given coordinates on a plane and run in straight lines to their respective destinations in a fixed amount of time. Both move at constant speed, so each person’s position is a linear interpolation between their start and end points.
We are given two arrays of length $n$, both containing the same multiset of values. The array is arranged in a circle, so position $n$ connects back to position $1$. We are allowed to cut some of the circular edges, which splits the circle into several contiguous linear segments.
Each employee is described by a pair of skills, how many lines of code they produce per hour and how many bugs they fix per hour.
We are looking at a process where a sequence of lootboxes is opened one after another. Each lootbox independently generates a random subset of up to $n$ possible “rare items”, and each item appears in a given box with probability $p$, independently from all other items and…
Each message is an interval with a fixed length, and we are free to choose when each interval starts. Once started, a message runs continuously for its duration, and many messages can run at the same time without interference.
We are given a grid map with walkable cells, blocked cells, and a single starting position. From that start, there was originally a sequence of moves in four directions that would take you along a shortest path structure toward a treasure location.
The central issue is that the original write-up appealed to an informal “black/white symmetry” without exhibiting the actual invariant structure.
We are given several rectangular chocolate bars, each with integer dimensions up to 6 by 6. Each bar can be repeatedly cut into smaller rectangles by making straight cuts along grid lines, and every cut splits one rectangle into two smaller integer rectangles.
We are given a sequence of daily measurements, where each day has a single integer value. For every day i, we want to compare that day with any earlier day j, including itself, and compute how large a “meaningful jump” in measurement is between those two days after…
We are given a connected undirected graph where each vertex represents a customs checkpoint. Moving through a checkpoint takes a certain amount of time, while traveling along roads takes no time.
We are given a graph on $n$ labeled chickens. The graph is extremely sparse, having exactly $n-2$ edges, and it is guaranteed to be a forest.
The input is completely degenerate: it always consists of a single placeholder character. There is no hidden structure, no parameters to interpret, and no variation across test cases. Every valid program is effectively being asked to choose between two conceptual actions.