Prime Sieve Methods: Sieve of Eratosthenes and Euler's Sieve

This article explains how to determine whether a number is prime, focusing on two efficient seiving algorithms. Sieve of Eratosthenes Before learning the Sieve of Eratosthenes, consider the naive trial division method for checking primality of each number: Naive Method #include <stdio.h> int main() { int st[100] = {0}; // 0 means pri ...

Posted on Wed, 16 Sep 2026 16:37:35 +0000 by datafan

Dynamic Programming: String Deletion and Edit Distance Problems

Delete Operation for Two Strings Problem Statement Given two strings word1 and word2, determine the minimum number of steps required to make both strings identical, where each step allows you to delete exactly one character from either string. Solution Approach This problem can be efficiently solved using dynamic programming. The key insight ...

Posted on Wed, 16 Sep 2026 16:15:54 +0000 by storyteller

Analyzing WeChat Withdrawal Fees with Java Code

A recent discussion about WeChat wallet withdrawal fees sparked an interesting algorithmic problem. The question: given a 0.1 yuan minimum fee per withdrawal (waived if balance is insufficient), how many operations are needed to transfer all money to WeChat as fees? Initial Experiments First, I verified the fee structure. Withdrawing 0.1 yuan i ...

Posted on Mon, 14 Sep 2026 16:45:56 +0000 by tomdchi

Implementing Linked List Operations: Removal, Design, and Reversal

Linked List Fundamentals Linked lists consist of nodes connected via pointers, differing from arrays in their non-contiguous memory allocation. Common variants include singly-linked, doubly-linked, and circular linked lists. A basic singly-linked list node structure in C++: struct ListNode { int value; ListNode* next; ListNode(int x ...

Posted on Mon, 14 Sep 2026 16:06:27 +0000 by AcousticJames

C++ STL Partition Algorithms: Understanding partition(), partition_copy(), stable_partition(), and partition_point()

The C++ Standard Template Library provides several powerful algorithms for reorganizing container elemants based on predicate conditions. Among these, the partition family of algorithms offers flexible mechanisms for dividing sequences into two groups. partition() The partition() algorithm rearranges elements within a given range, separating th ...

Posted on Sun, 13 Sep 2026 16:11:05 +0000 by twister47

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

Solutions to AtCoder Beginner Contest 055 Problems

Problem A Each meal costs 800 yen. For every 15 meals purchased, a refund of 200 yen is issued. Given $ x $, the total number of meals consumed, compute the net expenditure. The formula is: $$ 800x - \left\lfloor \frac{x}{15} \right\rfloor \cdot 200 $$ Problem B After $ N $ workouts, where initial strength is 1 and each $ i $-th workout multipl ...

Posted on Fri, 11 Sep 2026 16:45:57 +0000 by YOUAREtehSCENE

Optimizing Range Updates with Difference Arrays

A difference array transforms sequential update operations into constant-time modifications by recording only the boundary changes between adjacent elements. Given an original sequence A, its corresponding difference sequence D is defined such that D[0] = A[0] and D[i] = A[i] - A[i-1] for i > 0. Recovering the original sequence simply requir ...

Posted on Thu, 10 Sep 2026 16:29:13 +0000 by everlifefree

Identifying the Tournament Champion

Problem Description In a tournament with n teams, numbered from 0 to n-1, a n x n boolean matrix grid is providde. The value grid\[i\]\[j\] indicates the outcome of a match between team i and team j. If grid\[i\]\[j\] == 1, team i is considered stronger than team j. The task is to identify the champion team, which is defined as the team that no ...

Posted on Wed, 09 Sep 2026 16:52:22 +0000 by appels

Binary Lifting for LCA Queries

Directory Preprocessing LCA External Function Version Preprocessing void solve() { int n, k; cin >> n >> k; vector<vector<int>> adj(n + 1); for (int i = 1; i <= n - 1; ++i) { int x, y; cin >> x >> y; adj[x].push_back(y); adj[y].push_back(x); } vecto ...

Posted on Tue, 08 Sep 2026 16:35:03 +0000 by FadeOut79