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

Essential Algorithm Implementations in C++

Number Theory Fast Exponentiation Computes base raised to the power of exp modulo mod efficiently using binary decomposition. long long fast_power(long long base, long long exp, long long mod) { long long result = 1; base %= mod; while (exp > 0) { if (exp & 1) result = (result * base) % mod; base = (base * bas ...

Posted on Wed, 05 Aug 2026 16:13:30 +0000 by cherubrock74

Java Programming Fundamentals: Practical Exercises for Beginners

When entering the world of Java programming, a solid foundation is the first step toward success. To help you build a strong programming basse, we've designed a series of Java fundamental exercises aimed at mastering the core concepts and programming techniques of the language. Whether you're a beginner or a developer looking to strengthen your ...

Posted on Tue, 30 Jun 2026 16:39:12 +0000 by sjaccaud

Large Integer Primality Testing and Factorization Algorithms

Miller-Rabin Primality TestThe Miller-Rabin algorithm is a probabilistic method used to determine if a large number is prime. It builds upon Fermat's Little Theorem, which states that for a prime $ p $ and integer $ a $ such that $ 1 \le a < p $, the congruence $ a^{p-1} \equiv 1 \pmod p $ holds. However, relying solely on this theorem allows f ...

Posted on Thu, 11 Jun 2026 16:38:34 +0000 by jl

Möbius Inversion and Dirichlet Convolution in Number Theory

Dirichlet Convolution Dirichlet convolution is a binary operation defined between arithmetic functions. It can be expressed as \((f * g)(n) = \sum_{xy = n} f(x) \cdot g(y)\) or equivalently \((f * g)(n) = \sum_{d \mid n} f(d) \cdot g(\frac{n}{d})\). Properties If both \(f\) and \(g\) are multiplicative functions, then \(f * g\) is also multipl ...

Posted on Thu, 11 Jun 2026 16:09:41 +0000 by niwa3836

GESP Practice Problems: Reading, Scheduling, Geometry, and Bit Patterns

Holiday Reading A book has n pages. A student can read at most k pages per day over t vacation days. The maximum number of pages they can finish is the smaller of n and k * t. n = int(input()) k = int(input()) t = int(input()) print(min(n, k * t)) Shared Duty Schedule Two students clean on cycles of m and n days. The next time they coincide i ...

Posted on Sun, 07 Jun 2026 17:44:57 +0000 by cmanhatton

Efficient Algorithms for GCD Pair Counting, Incremental Construction, and Circular Coloring

Counting GCD Pairs in Dynamic Multisets Maintain a multiset of positive integers with insertion and deletion operations. For each query, count unordered pairs (i, j) where i ≠ j and gcd(i, j) = k. Constraints: n, V ≤ 10^5. Conisder the change in answer count: $$\sum_{i=1}^{V}c_i[\gcd(i,x)=k]$$ Let x' = x/k: $$\sum_{i=1}^{\lfloor V/k \rfloor}c_{ ...

Posted on Sat, 06 Jun 2026 17:32:00 +0000 by dhruvasagar