Core NumPy Array Techniques and Data Handling

Generating Arrays import numpy as np # Create a filled vector vec_ones = np.ones(3) # Create a zeroed vector vec_zeros = np.zeros(3) # Fill specific shape with value filled_matrix = np.full(shape=(3, 2), fill_value=5) # Generate sequence with step counter = np.arange(start=0, stop=5, step=2) # Random integers in range rand_int_arr = np.ran ...

Posted on Sat, 07 Nov 2026 16:42:47 +0000 by m00nz00mer

Solving a Competitive Programming Contest: Problem Analyses and Solutions

Problem T1: Geometry and Distances The first problem involves calculating two distances. The first is the distance from a given point to a line segment, and the second is the distance from the same point to a circle. The distance to the circle is straightforward: it's the distance from the point to the circle's center minus the radius. For the ...

Posted on Sat, 24 Oct 2026 16:14:38 +0000 by sv4rog

Computing Ancestors with Coprime Values in a Tree Using DFS

Given an undirceted tree consisting of n nodes numbered from 0 to n - 1, each node has an associated value. The task is to compute for each node the nearest ancestor whose value is coprime with the current node's value. Two numbers are coprime if their greatest common divisor (GCD) is 1. The solution uses depth-first search (DFS) traversal stat ...

Posted on Wed, 21 Oct 2026 16:24:41 +0000 by raydona

Determining Representability of an Integer as a Sum of 2020 and 2021 Multiples

Given a positive integer $ n $, determine whether it can be expressed as a non-negative integer combination of 2020 and 2021 — that is, whether there exist integers $ a \geq 0 $ and $ b \geq 0 $ such that: $$ n = 2020a + 2021b $$ Rewriting the equation reveals a useful structure: $$ n = 2020(a + b) + b = 2020k + b, $$ where $ k = a + b $. Since ...

Posted on Wed, 14 Oct 2026 16:39:25 +0000 by Spiz

Efficient Exponentiation Using Fast Power Algorithm

The fast power algorithm is designed to compute large exponentiations efficiently, reducing time complexity from O(b) to O(log b). This method is particularly useful when dealing with modular arithmetic, such as calculating a^b mod m. Core Principle The fundamental idea relies on binary representation of the exponent. For any integer b, we can ...

Posted on Fri, 02 Oct 2026 16:38:07 +0000 by modigy

Essential Mathematics for Competitive Programming

Integer Summation and Overflow Prevention The formula for the sum of the first n natural numbers is SUM = n * (n + 1) / 2. However, performing multiplication before division may cause integer overflow even if the final result fits within the data type. Mitigation strategies: Use a 64-bit integer type such as long long. Rearrange the computatio ...

Posted on Sat, 26 Sep 2026 16:27:03 +0000 by CoreyR

Counting GCD Values in Range Using Integer Division Block

Given integers l, r, and k, determine how many distinct greatest common divisors (GCDs) can be formed by selecting any k numbers from the range [l, r]. The constraint is: 1 ≤ l ≤ r ≤ 10^12, 2 ≤ k ≤ r - l + 1. Rather than computing all possible GCD values directly, we count all potential divisors. Any integer m = i × j that divides two numbers x ...

Posted on Thu, 27 Aug 2026 16:53:21 +0000 by AMCH

Building Python Proficiency Through Equation Solving

Solving Linear and Quadratic Equations to Explore Core Python Concepts This approach uses mathematical problem solving as a unifying thread to introduce foundational Python constructs—starting from basic syntax and progressing through functions, object-oriented design, error handling, and modularization. Linear Equations in One Variable from sy ...

Posted on Sat, 08 Aug 2026 16:55:39 +0000 by Knutty

Applying Expected Value in Algorithm Design

Expected value is a fundamental concept in probability theory and statistics, used to describe the average or central tendency of data. In computer algorithm competitions, expected value algorithms are considered medium to advanced level, playing a crucial role in programming. In recent years, problems involving expectations and expectation dyn ...

Posted on Sat, 01 Aug 2026 16:42:30 +0000 by zak

Programming Competition Problem Solutions and Analysis

Mathematical Caclulation Problem Given the formula for distance between a point and a line, we can simpliyf the calculation to |x-y| * 50: #include <iostream> #include <cmath> int main() { int x, y; std::cin >> x >> y; std::cout << abs(y - x) * 50 << '\n'; return 0; } String Output Problem S ...

Posted on Fri, 19 Jun 2026 18:14:18 +0000 by jantheman