Mobius Function and Inversion Principles
Mobius Function
Definition
\[\mu(n) = \begin{cases} 1 & n = 1 \\ 0 & n \text{ has squared prime factors} \\ (-1)^k & \text{where } k \text{ is the count of distinct prime factors of } n \end{cases}\]
Properties
The Mobius function is multilpicative:
\[\sum_{d \mid n} \mu(d) = \varepsilon(n) \\ \mu \ast 1 = \varepsilon\]
where \(\var ...
Posted on Mon, 02 Nov 2026 16:21:28 +0000 by Hurklefish
Foundations of Number Theory and Combinatorial Algorithms
1.1 Basic Sieve Approach
The fundamental strategy involves iterating through integers starting from 2 and marking all their multiples as composite. Because a prime number is divisible only by 1 and itself, it remains unmarked. The total operations correspond to the sum of the harmonic series ($\frac{n}{2} + \frac{n}{3} + \dots$), yielding a tim ...
Posted on Wed, 28 Oct 2026 16:45:08 +0000 by Axeia
Solving Polynomial Equations with Modular Arithmetic
Rewriting the Polynomial
Directly solving high-degree polynomials is computationally infeasible due to the lack of general root-finding formulas. Instead, we restructure the expression by factoring out terms:
Modular Evaluation Strategy
To verify whether a value of x satisfies the equation, we evaluate \(f(x) \bmod p\), where p is a large prim ...
Posted on Wed, 21 Oct 2026 16:27:54 +0000 by jwk811
Determining Representability of an Integer as a Sum of 2020 and 2021 Multiples
Given a positive integer $ n $, determine whether it can be expressed as a non-negative integer combination of 2020 and 2021 — that is, whether there exist integers $ a \geq 0 $ and $ b \geq 0 $ such that:
$$
n = 2020a + 2021b
$$
Rewriting the equation reveals a useful structure:
$$
n = 2020(a + b) + b = 2020k + b,
$$
where $ k = a + b $. Since ...
Posted on Wed, 14 Oct 2026 16:39:25 +0000 by Spiz
Essential Algorithm Templates for Competitive Programming
Linear Sieve for Prime Numbers (O(2N))
bool composite[N];
int primes[N], prime_count;
void build_sieve(int limit) {
for (int num = 2; num <= limit; num++) {
if (!composite[num]) {
primes[prime_count++] = num;
}
for (int j = 0; j < prime_count && num * primes[j] <= limit; j++) {
...
Posted on Mon, 12 Oct 2026 16:14:11 +0000 by synstealth
Winter Algorithm Bootcamp 2025 – Session 3 Solutions
Chino’s Take-Away Game
The game ends when only one stone remains. If the initial pile contains an odd count, the first player can always remove exactly one stone, leaving an even number. Any subsequent move by the second player must remove an odd amount (co-prime with the even remainder), again leaving an odd count. By induction the first playe ...
Posted on Mon, 05 Oct 2026 16:32:04 +0000 by Batosi
Counting GCD Values in Range Using Integer Division Block
Given integers l, r, and k, determine how many distinct greatest common divisors (GCDs) can be formed by selecting any k numbers from the range [l, r].
The constraint is: 1 ≤ l ≤ r ≤ 10^12, 2 ≤ k ≤ r - l + 1.
Rather than computing all possible GCD values directly, we count all potential divisors. Any integer m = i × j that divides two numbers x ...
Posted on Thu, 27 Aug 2026 16:53:21 +0000 by AMCH
Solving Math and Graph Problems from a Competitive Programming Contest
Problem 1: Counting Valid Pairs with LCM Condition
Problem Description
Given an integer n where 1 ≤ n ≤ 10^8, determine the number of pairs (x, y) such that 1 ≤ x, y ≤ n and the following inequality holds:
lcm(x, y) / gcd(x, y) ≤ 3
Note that lcm(x, y) = (x * y) / gcd(x, y)^2.
Solution Approach
This is a straightforward number theory problem. L ...
Posted on Mon, 10 Aug 2026 16:39:42 +0000 by HaVoC
Advanced Algorithmic Strategies: Subtree DP Reconstruction and Prime-Power Modular Counting
Subtree Budget Allocation and Optimal Path Reconstruction
The core challenge revolves around allocating a fixed budget across a binary tree structure to maximize a specific threshold value. The solution begins by analyzing the root's contribution and propagating constraints downward. We define a dynamic programming state dp_max[u][b] representi ...
Posted on Fri, 07 Aug 2026 16:35:09 +0000 by arun4444
Solving the Ternary Goldbach Conjecture via Sieve of Eratosthenes
The Ternary Goldbach Conjecture asserts that any odd integer greater than 7 can be represented as the sum of three prime numbers. While proven for sufficiently large numbers, verifying this for smaller integers requires an effiicent computational approach. Given an odd integer n (9 < n < 20,000), our objective is to find a triplet of prim ...
Posted on Thu, 06 Aug 2026 16:46:07 +0000 by santrowithu