Computing All Integer Factors in Ascending Order with Rust
A straightforward Rust implementation for finding all factors of a number is shown below. This approach iterates up to the square root of the input value.
fn compute_factors_simple(num: u64) -> Vec<u64> {
let sqrt_val = (num as f64).sqrt().floor() as u64;
let mut factors = Vec::new();
for divisor in 1..=sqrt_val {
i ...
Posted on Tue, 28 Jul 2026 16:25:21 +0000 by pazzy
Algorithmic Solutions for Nowcoder Weekly Contest Round 6
Problem A: Counting Digit Holes
The task requires calculating the total number of closed loops (holes) in a sequence of digits. Digits '0', '6', and '9' contain one loop each, while '8' contains two loops. The solution involves iterating through the string and accumulating the count based on the digit encountered.
#include <iostream>
#inc ...
Posted on Mon, 06 Jul 2026 17:24:28 +0000 by briand
Essential Mathematical Algorithms for Programming
Fast Exponentiation
Recursive Approach
function fastExponentiation(base, exponent, modulus) {
if (exponent === 0) return 1;
const halfExp = fastExponentiation(base, Math.floor(exponent / 2), modulus);
let result = (halfExp * halfExp) % modulus;
if (exponent % 2 === 1) {
result = (result * base) % modulus;
...
Posted on Wed, 01 Jul 2026 17:48:25 +0000 by varghesedxb
The Universal Euclidean Algorithm: Computing RU Strings and Summation Problems
Introduction
Consider the following geometric problem: mark all vertical lines x = c and horizontal lines y = c where c ∈ ℤ on a plane. Now consider a line y = (px + r)/q where p, r ∈ ℕ and q ∈ ℕ₊. Since the residue class of r modulo q determines the behavior, we can assume r < q without loss of generality.
Imagine a moving point traveling a ...
Posted on Sun, 28 Jun 2026 18:06:32 +0000 by gli
Technical Analysis of Xiangtan University Spring 2023 Freshman Programming Contest
Problem A: Strategic Allocation
This challenge involves selecting a subset of items to meet a weight capacity requirement with the minimum count. The optimal approach utilizes a greedy strategy. By prioritizing larger weights first, we minimize the number of items required to reach the target threshold.
void processAllocation() {
int itemCo ...
Posted on Sat, 27 Jun 2026 16:02:21 +0000 by mattpointblank
Counting Valid 2x2 Submatrices and Optimizing Zero-Prefix Products
To solve this problem, we scan every possible 2x2 submatrix in a n × m grid and check whether the four characters within it collectively contain at least one 'y', one 'o', and one 'u'. The order does not matter—only the presence of all three required characters.
The algorithm iterates over all valid top-left corners of 2x2 blocks (from row 1 to ...
Posted on Wed, 24 Jun 2026 17:58:58 +0000 by webdes03
Algorithm Solutions for Codeforces Educational Round 164
A. Ribbon Coloring Strategy
Alice's optimal strategy is to color the ribbon in a repeating pattern like "123123...". Bob's optimal counter-strategy is to recolor the ribbon to the most frequent color.
The most frequent color appears at least ⌈n/m⌉ times, leaving Bob with at most (n - ⌈n/m⌉) recoloring operations. Compare this value wi ...
Posted on Fri, 19 Jun 2026 16:00:53 +0000 by []InTeR[]
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
Optimization and Strategy Problems on Sequences and Grids
Resource Redistribution with Asymmetric Operations
Given a sequence (a) of length (n) and two positive integers (x, y) where (y \le x). You may repeatedly pick two elements and transfer resources: subtract (x) from one and add (y) to the other, provided the first remains non‑negative. Determine the maximum possible value of any element after op ...
Posted on Tue, 09 Jun 2026 17:33:25 +0000 by obesechicken13