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

Algorithmic Patterns and Applications in Tree Dynamic Programming

Tree-based dynamic programming relies on post-order traversal (processing children before parents). The standard recursive skeleton ensures proper state aggregation without cyclic revisits: void traverse(int current_node, int parent_node) { // Process leaf/base case initialization if necessary for (auto& edge : adjacency_list[c ...

Posted on Sat, 09 May 2026 08:47:34 +0000 by joebWI