brain

tamnd's digital brain — notes, problems, research

43815 notes

Project Euler Problem 967

nA positive integer n is considered B-trivisible if the sum of all different prime factors of n which are not larger tha

eulermathematicscompetitive-programming
LeetCode 9 - Palindrome Number

The problem asks us to determine whether a given integer reads the same forward and backward. Such numbers are called palindromes. For example, the number 121 is a palindrome because reversing its digits still produces 121.

leetcodeeasymath
Project Euler Problem 936

A peerless tree is a tree with no edge between two vertices of the same degree.

eulermathematicscompetitive-programming
LeetCode 1 - Two Sum

The problem gives us an integer array called nums and another integer called target. Our task is to find two different elements in the array whose sum equals target, then return their indices.

leetcodeeasyarrayhash-table
Project Euler Problem 986

Solution to Project Euler Problem 986.

eulermathematicscompetitive-programming
LeetCode 209 - Minimum Size Subarray Sum

The problem gives us an array of positive integers called nums and a positive integer called target. We need to find the smallest possible length of a contiguous subarray whose sum is greater than or equal to target.

leetcodemediumarraybinary-searchsliding-windowprefix-sum
Project Euler Problem 891

A round clock only has three hands: hour, minute, second.

eulermathematicscompetitive-programming
LeetCode 204 - Count Primes

The problem asks us to count how many prime numbers exist that are strictly smaller than a given integer n. A prime number is a positive integer greater than 1 that has exactly two divisors: 1 and itself. Examples of prime numbers include 2, 3, 5, 7, and 11.

leetcodemediumarraymathenumerationnumber-theory
Project Euler Problem 364

There are N seats in a row.

eulermathematicscompetitive-programming
Project Euler Problem 931

For a positive integer n construct a graph using all the divisors of n as the vertices.

eulermathematicscompetitive-programming
CF 4B - Before an Exam

We are given d days and a target total number of study hours, sumTime. For every day, Peter must study at least minTime[i] hours and at most maxTime[i] hours. The task is to construct any valid schedule whose total sum is exactly sumTime.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1941B - Rudolf and 121

We are given an array of non-negative integers. In one operation, we choose an index $i$ such that $2 le i le n-1$, and

codeforcescompetitive-programmingbrute-forcedpgreedymath
Project Euler Problem 998

The minimum bounding square of a triangle is the smallest square that can be drawn which fully covers the triangle.

eulermathematicscompetitive-programming
Project Euler Problem 927

A full k-ary tree is a tree with a single root node, such that every node is either a leaf or has exactly k ordered chil

eulermathematicscompetitive-programming
Project Euler Problem 990

Solution to Project Euler Problem 990.

eulermathematicscompetitive-programming
LeetCode 13 - Roman to Integer

The problem gives a Roman numeral string and asks us to convert it into its corresponding integer value. Roman numerals use seven symbols: Symbol Value --- --- I 1 V 5 X 10 L 50 C 100 D 500 M 1000 Most Roman numerals follow a simple additive rule.

leetcodeeasyhash-tablemathstring
Project Euler Problem 963

NOTE: This problem is related to Problem 882.

eulermathematicscompetitive-programming
Project Euler Problem 929

A composition of n is a sequence of positive integers which sum to n.

eulermathematicscompetitive-programming
Project Euler Problem 4

A palindromic number reads the same both ways.

eulermathematicscompetitive-programming
Project Euler Problem 792

We define nu2(n) to be the largest integer r such that 2^r divides n.

eulermathematicscompetitive-programming
Project Euler Problem 312

- A Sierpiński graph of order-1 (S1) is an equilateral triangle.

eulermathematicscompetitive-programming
Project Euler Problem 932

For the year 2025 Given positive integers a and b, the concatenation ab we call a 2025-number if ab = (a+b)^2.

eulermathematicscompetitive-programming
LeetCode 3 - Longest Substring Without Repeating Characters

The problem gives a string s and asks for the length of the longest substring that contains no repeated characters. A substring is a continuous section of the string. This detail matters because characters must remain adjacent.

leetcodemediumhash-tablestringsliding-window
Project Euler Problem 726

Consider a stack of bottles of wine.

eulermathematicscompetitive-programming
LeetCode 192 - Word Frequency

This problem asks us to write a shell script that reads a text file named words.txt and computes how many times each word appears. After counting the occurrences, the script must print every unique word together with its frequency, sorted in descending order of frequency.

leetcodemediumshell
Project Euler Problem 521

Let operatorname{smpf}(n) be the smallest prime factor of n.

eulermathematicscompetitive-programming
Project Euler Problem 937

Let theta=sqrt{-2}. Define T to be the set of numbers of the form a+btheta, where a and b are integers and either agt 0,

eulermathematicscompetitive-programming
Project Euler Problem 576

A bouncing point moves counterclockwise along a circle with circumference 1 with jumps of constant length l lt 1, until

eulermathematicscompetitive-programming
CF 1941C - Rudolf and the Ugly String

We are given a string and want to remove the minimum number of characters so that the resulting string no longer contains "pie" or "map" as a substring.

codeforcescompetitive-programmingdpgreedystrings
LeetCode 210 - Course Schedule II

This problem asks us to determine a valid order in which courses can be completed given prerequisite relationships between them. You are given numCourses, which represents the total number of courses labeled from 0 to numCourses - 1.

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theorytopological-sort
LeetCode 193 - Valid Phone Numbers

This problem asks us to process a text file named file.txt and print only the phone numbers that match one of two valid formats. The valid formats are: and In both formats, every x represents a single digit from 0 to 9.

leetcodeeasyshell
Project Euler Problem 969

nStarting at zero, a kangaroo hops along the real number line in the positive direction.

eulermathematicscompetitive-programming
LeetCode 8 - String to Integer (atoi)

The problem asks us to implement a simplified version of the C/C++ atoi function, which converts a string into a 32-bit signed integer. The conversion process is strict and follows several rules in a specific order.

leetcodemediumstring
Project Euler Problem 974

Solution to Project Euler Problem 974.

eulermathematicscompetitive-programming
Project Euler Problem 474

For a positive integer n and digits d, we define F(n, d) as the number of the divisors of n whose last digits equal d.

eulermathematicscompetitive-programming
Project Euler Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.

eulermathematicscompetitive-programming
LeetCode 164 - Maximum Gap

The problem asks us to compute the largest difference between two consecutive elements after sorting the array. At first glance, this may seem straightforward: sort the array, then scan through adjacent pairs to find the maximum difference.

leetcodemediumarraysortingbucket-sortradix-sort
Project Euler Problem 980

Solution to Project Euler Problem 980.

eulermathematicscompetitive-programming
Project Euler Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms.

eulermathematicscompetitive-programming
LeetCode 202 - Happy Number

This problem asks us to determine whether a given positive integer n is a happy number. A happy number is defined through a repeated transformation process. Starting with the original number, we repeatedly replace it with the sum of the squares of its digits.

leetcodeeasyhash-tablemathtwo-pointers
Project Euler Problem 968

nDefinennas the sum of 2^a3^b5^c7^d11^e over all quintuples of non-negative integers (a, b, c, d, e) such that the sum o

eulermathematicscompetitive-programming
Project Euler Problem 384

Define the sequence a(n) as the number of adjacent pairs of ones in the binary expansion of n (possibly overlapping).

eulermathematicscompetitive-programming
Project Euler Problem 976

Solution to Project Euler Problem 976.

eulermathematicscompetitive-programming
Project Euler Problem 784

Let's call a pair of positive integers p, q (p lt q) reciprocal, if there is a positive integer rlt p such that r equals

eulermathematicscompetitive-programming
Project Euler Problem 919

We call a triangle fortunate if it has integral sides and at least one of its vertices has the property that the distanc

eulermathematicscompetitive-programming
Project Euler Problem 9

A Pythagorean triplet is a set of three natural numbers, a lt b lt c, for which, For example, 3^2 + 4^2 = 9 + 16 = 25 =

eulermathematicscompetitive-programming
Project Euler Problem 935

A square of side length b<1 is rolling around the inside of a larger square of side length 1, always touching the larger

eulermathematicscompetitive-programming
Project Euler Problem 914

For a given integer R consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with

eulermathematicscompetitive-programming
LeetCode 6 - Zigzag Conversion

The problem asks us to transform a string into a zigzag pattern across a fixed number of rows, then read the characters row by row to produce the final result.

leetcodemediumstring
LeetCode 194 - Transpose File

This problem asks us to transpose the contents of a text file. Transposing means converting rows into columns and columns into rows. Every word in the input file is separated by a single space, and each row contains the same number of columns. The input is a file named file.txt.

leetcodemediumshell
Project Euler Problem 994

Solution to Project Euler Problem 994.

eulermathematicscompetitive-programming
Project Euler Problem 964

A group of k(k-1) / 2 + 1 children play a game of k rounds.nAt the beginning, they are all seated on chairs arranged in

eulermathematicscompetitive-programming
Project Euler Problem 893

Define M(n) to be the minimum number of matchsticks needed to represent the number n.

eulermathematicscompetitive-programming
LeetCode 195 - Tenth Line

This problem asks us to print exactly the 10th line from a text file named file.txt. The file contains multiple lines of plain text, and each line is separated by a newline character. The input is not provided as function arguments like many algorithm problems.

leetcodeeasyshell
Project Euler Problem 996

Solution to Project Euler Problem 996.

eulermathematicscompetitive-programming
Project Euler Problem 861

A unitary divisor of a positive integer n is a divisor d of n such that gcdleft(d,frac{n}{d}right)=1.

eulermathematicscompetitive-programming
Project Euler Problem 908

A clock sequence is a periodic sequence of positive integers that can be broken into contiguous segments such that the s

eulermathematicscompetitive-programming
Project Euler Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

eulermathematicscompetitive-programming
Project Euler Problem 957

There is a plane on which all points are initially white, except three red points and two blue points.

eulermathematicscompetitive-programming
Project Euler Problem 899

Two players play a game with two piles of stones.

eulermathematicscompetitive-programming
Project Euler Problem 910

An L-expression is defined as any one of the following: - a natural number; - the symbol A; - the symbol Z; - the symbol

eulermathematicscompetitive-programming
Project Euler Problem 938

A deck of cards contains R red cards and B black cards.

eulermathematicscompetitive-programming
Project Euler Problem 930

Given nge 2 bowls arranged in a circle, mge 2 balls are distributed amongst them.

eulermathematicscompetitive-programming
Project Euler Problem 296

Given is an integer sided triangle ABC with BC le AC le AB.

eulermathematicscompetitive-programming
Project Euler Problem 912

Let sn be the n-th positive integer that does not contain three consecutive ones in its binary representation.

eulermathematicscompetitive-programming
Project Euler Problem 933

Starting with one piece of integer-sized rectangle paper, two players make moves in turn.

eulermathematicscompetitive-programming
LeetCode 203 - Remove Linked List Elements

The problem asks us to remove every node from a singly linked list whose value is equal to a given integer val. After all matching nodes are removed, we must return the head of the modified linked list.

leetcodeeasylinked-listrecursion
Project Euler Problem 260

A game is played with three piles of stones and two players.

eulermathematicscompetitive-programming
Project Euler Problem 972

nThe hyperbolic plane can be represented by the open unit disc, namely the set of points (x, y) in Bbb R^2 with x^2 + y^

eulermathematicscompetitive-programming
Project Euler Problem 984

Solution to Project Euler Problem 984.

eulermathematicscompetitive-programming
Project Euler Problem 921

Consider the following recurrence relation: Note that a0 is the golden ratio.

eulermathematicscompetitive-programming
LeetCode 205 - Isomorphic Strings

The problem asks us to determine whether two strings, s and t, are isomorphic. Two strings are considered isomorphic if there exists a one-to-one mapping between characters in s and characters in t such that replacing every character in s according to this mapping produces t.

leetcodeeasyhash-tablestring
Project Euler Problem 916

Let P(n) be the number of permutations of 1,2,3,ldots,2n such that: 1.

eulermathematicscompetitive-programming
Project Euler Problem 534

The classical eight queens puzzle is the well known problem of placing eight chess queens on an 8 times 8 chessboard so

eulermathematicscompetitive-programming
Project Euler Problem 988

Solution to Project Euler Problem 988.

eulermathematicscompetitive-programming
Project Euler Problem 906

Three friends attempt to collectively choose one of n options, labeled 1,dots,n, based upon their individual preferences

eulermathematicscompetitive-programming
Project Euler Problem 962

Given is an integer sided triangle ABC with BC le AC le AB.nk is the angular bisector of angle ACB.nm is the tangent at

eulermathematicscompetitive-programming
Project Euler Problem 369

In a standard 52 card deck of playing cards, a set of 4 cards is a Badugi if it contains 4 cards with no pairs and no tw

eulermathematicscompetitive-programming
Project Euler Problem 966

nLet I(a, b, c) be the largest possible area of intersection between a triangle of side lengths a, b, c and a circle whi

eulermathematicscompetitive-programming
LeetCode 207 - Course Schedule

This problem models course dependencies as a directed graph. Each course is represented as a node, and each prerequisite relationship is represented as a directed edge. If prerequisites[i] = [a, b], that means course b must be completed before course a.

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theorytopological-sort
Project Euler Problem 900

Two players play a game with at least two piles of stones.

eulermathematicscompetitive-programming
Project Euler Problem 134

Consider the consecutive primes p1 = 19 and p2 = 23.

eulermathematicscompetitive-programming
Project Euler Problem 94

It is easily proved that no equilateral triangle exists with integral length sides and integral area.

eulermathematicscompetitive-programming
Project Euler Problem 598

Consider the number 48.

eulermathematicscompetitive-programming
Project Euler Problem 849

In a tournament there are n teams and each team plays each other team twice.

eulermathematicscompetitive-programming
Project Euler Problem 482

ABC is an integer sided triangle with incenter I and perimeter p.

eulermathematicscompetitive-programming
Project Euler Problem 728

Consider n coins arranged in a circle where each coin shows heads or tails.

eulermathematicscompetitive-programming
Project Euler Problem 184

Consider the set Ir of points (x,y) with integer co-ordinates in the interior of the circle with radius r, centered at t

eulermathematicscompetitive-programming
Project Euler Problem 165

A segment is uniquely defined by its two endpoints.

eulermathematicscompetitive-programming
Project Euler Problem 230

For any two strings of digits, A and B, we define F{A, B} to be the sequence (A,B,AB,BAB,ABBAB,dots) in which each term

eulermathematicscompetitive-programming
Project Euler Problem 53

There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 In

eulermathematicscompetitive-programming
Project Euler Problem 510

Circles A and B are tangent to each other and to line L at three distinct points.

eulermathematicscompetitive-programming
Project Euler Problem 767

A window into a matrix is a contiguous sub matrix.

eulermathematicscompetitive-programming
Project Euler Problem 183

Let N be a positive integer and let N be split into k equal parts, r = N/k, so that N = r + r + cdots + r.

eulermathematicscompetitive-programming
Project Euler Problem 465

The kernel of a polygon is defined by the set of points from which the entire polygon's boundary is visible.

eulermathematicscompetitive-programming
Project Euler Problem 872

A sequence of rooted trees Tn is constructed such that Tn has n nodes numbered 1 to n.

eulermathematicscompetitive-programming
Project Euler Problem 274

For each integer p gt 1 coprime to 10 there is a positive divisibility multiplier m lt p which preserves divisibility by

eulermathematicscompetitive-programming
Project Euler Problem 162

In the hexadecimal number system numbers are represented using 16 different digits: The hexadecimal number mathrm{AF} wh

eulermathematicscompetitive-programming
Project Euler Problem 293

An even positive integer N will be called admissible, if it is a power of 2 or its distinct prime factors are consecutiv

eulermathematicscompetitive-programming
Project Euler Problem 660

We call an integer sided triangle n-pandigital if it contains one angle of 120 degrees and, when the sides of the triang

eulermathematicscompetitive-programming