Latin America Regional Programming Contest Solutions: Advanced Algorithm Techniques
Problem D: DiviDuelo
Approach
This problem requires number theory analysis and prime factorization techniques. The solution involves categorizing cases based on the prime factorization of the input number. The implementation uses advanced primality testing and factorization algorithms including Miller-Rabin and Pollard's rho method.
Implementat ...
Posted on Thu, 18 Jun 2026 16:00:43 +0000 by sjaccaud
Essential Algorithm Templates in C++
Number Theory
Primality Testing via Trial Division
#include <iostream>
using namespace std;
bool isPrime(int num) {
if (num < 2) return false;
for (int d = 2; d <= num / d; ++d)
if (num % d == 0) return false;
return true;
}
int main() {
int queries;
cin >> queries;
while (queries--) {
...
Posted on Sat, 13 Jun 2026 17:12:21 +0000 by sebjlan
Heavy-Light Decomposition for Tree Operations
Heavy-Light Decomposition (HLD) is a powerful technique that partitions a rooted tree into a set of disjoint paths (chains). This transformation allows for efficient range-based operations (like updates and queries) on tree structures by mapping the nodes into a linear array using a Segment Tree.
Core Definitions
Heavy Edge: An edge connecting ...
Posted on Sun, 07 Jun 2026 17:42:18 +0000 by asunsha
SMU Summer 2024 Contest Round 4 - Problem Editorials
Made Up
Problem Statement Given three sequences A, B, C, count the number of pairs (i, j) such that A[i] = B[C[j]].
Solution Approach Since all values are bounded between 1 and N, we can use frequency counting. For each value v, count how many times it appears in array A (stored in cntA) and how many times it appears as B[C[j]] (stored in cntB) ...
Posted on Thu, 04 Jun 2026 16:57:11 +0000 by reyes99
Graph Theory: Multi-source and Single-source Shortest Path Algorithms
Shortest path problems in graph theory often rely on the concept of relaxation. Relaxation occurs when a path from node u to v can be shoretned by routing through an intermediate node k, i.e., if dist[u][v] > dist[u][k] + dist[k][v], we update dist[u][v] accordingly.
Floyd-Warshall Algorithm (All-Pairs Shortest Paths)
To compute shortest pat ...
Posted on Wed, 03 Jun 2026 18:20:34 +0000 by little_tris
Data Structures Exam Questions and Solutions
Multiple Choice Questions
Computer algorithms refer to:
A. Calculation methods
B. Problem-solving steps
C. Sorting methods
D. Scheduling methods
Answer: B
Comparde to linked lists, sequential lists:
A. Allow easier random access
B. Have more scatterde physical storage
C. Enable simpler insertions/deletions
D. Better fit linear logical structur ...
Posted on Sat, 30 May 2026 22:33:26 +0000 by KefkaIIV
2012 NOIP Popularization Group Finals Walkthrough
Task 1 – Factor Splitting
Given a positive integer n that is the product of two distinct primes, output the larger one.
Input: One integer n (≤ 2·109).
Output: The larger prime factor.
Observation: The first divisor (other than 1) must be the smaller prime, so the answer is n / i once the smallest i > 1 with n % i == 0 is found.
#include < ...
Posted on Thu, 28 May 2026 22:28:35 +0000 by dannyd
Identifying Edges on Shortest Paths in Directed Graphs
To determine which edges can lie on a shortest path from source S to target T in a directed graph, compute shortest distances from S to all nodes. Then, perform a reverse BFS starting from T on the transposed graph. For each dequeued node cur and its neighbor nex in the transposed graph, if Dist[nex] == Dist[cur] - weight(cur->nex) holds, th ...
Posted on Sat, 16 May 2026 15:21:00 +0000 by dustinnoe
Tree Root Transition Algorithms for Maximum Subtree Value
Problem A: Tree Value Maximization
Approach
Define subtree_value[i] as the value generated by the subtree rooted at node i: subtree_value[i] = subtree_size[i] + Σ subtree_value[j] for all children j of i. The initial selection of i as root gives subtree_size[i] value, followed by contributions from its subtrees.
Direct computation for each root ...
Posted on Thu, 14 May 2026 08:30:08 +0000 by zeb
Algorithmic Problem Solving: Maximum Independent Set, Bomb Chain Reactions, SG Functions, and Tree Queries
A
Given a sequence ${a_n}$, select the largest possible subset such that no two selected elements sum to a prime number.
Constraints: $T \leq 4$, $n \leq 750$, $a_i \leq 10^9$.
Identical values can be merged into counts. Note that at most one instance of 1 may be included.
This becomes a bipartite graph problem: odd numbers connect to the sourc ...
Posted on Thu, 14 May 2026 02:12:22 +0000 by supergrame