Digit DP: From Fundamentals to Implementation

Digit dynamic programming (digit DP) is a technique used to count numbers within a range ([l, r]) that satisfy specific digit-based constraints. The standard approach involves transforming the problem into computing (F(r) - F(l-1)), where (F(x)) counts valid numbers from 0 to (x). The solution typically uses memoized recursion over the digits o ...

Posted on Mon, 02 Nov 2026 16:39:23 +0000 by postmanager

Elementary Number Theory Study Notes

Introduction For a better reading experience? Prerequisite knowledge (obvious): \(\operatorname{lcm}(a,b)=\dfrac{ab}{\gcd(a,b)}\) Linear Sieve for Primes Click to view code``` bool visited[MAXN]; vector primes; long long result; void sieve(){ for(int i=2;i<=n;i++){ if(!visited[i]) primes.push_back(i); for(auto j:primes){ if(ij>n) break; v ...

Posted on Mon, 12 Oct 2026 16:24:24 +0000 by juniorbisono

Solutions for NOIP 2009: Password Decryption, Inverse GCD-LCM, Trade Profit, and Target Sudoku

Problem 1: Decrypting S Country's Military Cipher Description R and S are at war. R's spy, Xiao C, has obtained S's encryption rule: each uppercase letter maps to a unique uppercase letter (bijection). Given a known encrypted string and its original string, build the substitution table. Then translate a new intercepted encrypted string. If the ...

Posted on Mon, 05 Oct 2026 16:17:26 +0000 by justinjkiss

Analysis of Two Number Theory Problems: Set Construction and GCD Subsequence

Problem 1: Counting Valid Sets In this problem, the floor operation does not affect the correcntess, so a brute-force DFS approach is applicable. A critical observation: if the array contains the element \(1\), it must be skipped immediately. Otherwise, \(1\) could be selected infinitely many time, leading to incorrect results. Solution Code in ...

Posted on Mon, 05 Oct 2026 16:14:09 +0000 by marcel

Algorithmic Analysis of CSP-S Mock Contest: Graphs, Number Theory, and Data Structures

Competition Overview This mock contest featured relatively weak test data, allowing suboptimal solutions to score significantly higher than expected (often 50+ points above theoretical estimates). The official solutions sometimes relied heavily on pattern recognition and handling specific subtasks rather than pure algorithmic elegance. This hig ...

Posted on Sat, 03 Oct 2026 16:33:46 +0000 by sidney

Counting Common Terms in Two Arithmetic Progressions Within a Range

Given two arithmetic progressions $A_i = a_1 i + b_1$ and $B_i = a_2 i + b_2$ for $i \in \mathbb{N}$, and integers $l \leq r$, determine how many integers $n \in [l, r]$ appear in both sequences. We seek integer solutions $(x, y) \in \mathbb{N}^2$ to the equation: $$ a_1 x + b_1 = a_2 y + b_2 $$ Rewriting gives the linear Diophantine equation: ...

Posted on Fri, 02 Oct 2026 16:01:46 +0000 by robster

Calculating the Sum of Squared Binomial Coefficients

Problem DefinitionThe task involves processing multiple queries where, for a given integer n, we must compute the sum of squared binomial coefficients: $\sum_{i=0}^{n} \binom{n}{i}^2$. The result should be returned modulo $10^9 + 7$. Constraints allow for n up to $10^6$, necessitating an efficient algorithm.Naive Approach: Dynamic ProgrammingFo ...

Posted on Sat, 12 Sep 2026 16:44:55 +0000 by nogginj

Solution Set for the 2023 SMU RoboCom-CAIP Selection Contest

Problem A: Maximum Value Boundary Analysis In this problem, we need to calculate the sum of counts $f(k)$ for pairs $(i, j)$ that satisfy specific boundary conditions related to two arrays $A$ and $B$. Let $f(k)$ represent the number of valid pairs where the second index $j$ equals $k$. We define $last\_k$ as the index where the maximum value o ...

Posted on Fri, 04 Sep 2026 16:45:03 +0000 by dhaselho

Competitive Programming Techniques and Problem Analysis

Codeforces 1017D - Binary String Query Complexity: $\mathcal{O}((4^n+q) \log n)$ Distinct binary strings are limited to $2^n$. Precomputing distances between pairs allows for binary search queries. Codeforces 1080F - Colorful Graph Approach: Persistent Segment Tree / Sweep Line Treat this as a data structure challenge. By sweeping the right end ...

Posted on Fri, 28 Aug 2026 16:14:17 +0000 by CodeMama

Computing Valid Offsets for Invariant Greatest Common Divisor Using Euler's Totient Function

Problem Definition Given two positive integers base and modulus where base < modulus, determine the count of non-negative integers x such that 0 ≤ x < modulus and gcd(base, modulus) == gcd(base + x, modulus). Input Constraints Number of test cases: 1 ≤ T ≤ 50 Value range: 1 ≤ base < modulus ≤ 10^{10} Mathematical Reduction Let d = gc ...

Posted on Thu, 06 Aug 2026 16:53:53 +0000 by woza_uk