Dynamic Programming Solutions for Three Algorithmic Problems
Ehab and the Expected GCD Problem
The key insight is that the first element should have the maximum number of prime factors, and subsequent elements should remove at most one prime factor per step for optimality. The smallest prime factors are 2 and 3, and using 3 more than once is suboptimal (e.g., 5 can be replaced by 2² for better results). ...
Posted on Fri, 17 Jul 2026 17:02:09 +0000 by RossC0
Algorithm Solutions for Competitive Programming Problems
Modular Division of Large Numbers
This solution demonstrates how to perform division operations with large numbers under a specific modulus using Fermat's Little Theorem. The approach converts string representations of numbers into numerical arrays and applies modular arithmetic properties.
#include <iostream>
#include <cstdio>
#inc ...
Posted on Tue, 14 Jul 2026 17:29:01 +0000 by modcar
Fraction and Complex Number Class Implementation with Operator Overloading
Fraction Class with Addition Operator
Define a class Rational to represent fractoins using two private integer members: numerator and denominator. The denominator is always positive, witth the sign of the fraction determined solely by the numerator. Implement operator overloading for addition (+) to sum two fractions and return the result in it ...
Posted on Wed, 24 Jun 2026 18:29:13 +0000 by jenp
AtCoder Beginner Contest 060 - Problem Solutions
Given three strings A, B, and C, determine whether the last character of A matches the first character of B, and the last character of B matches the first character of C. Each string consists of lowercase letters and is provided on a single line separated by spaces.
Solution Approach:
Extract the relevant characters and perform two comparisons. ...
Posted on Wed, 24 Jun 2026 16:26:26 +0000 by fiddlehead_cons
Optimizing String Construction and GCD Generation for Competitive Programming
To maximizee the number of positive votes, we can separate reviews into two groups: one for negative ratings (value 2) and another for all others. Since negative reviews contribute nothing to the total, we simply count all non-negatvie ratings.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
...
Posted on Sat, 06 Jun 2026 16:47:02 +0000 by plasmahba
Solution: PAROVI - Counting Segment Coverings with Coprime Pairs
Problem Analysis
Given (n) where (1 \le n \le 20), we need to count the number of ways to completely cover the interval ([1, n]) using segments where each segment connects two coprime numbers.
First, preprocess all coprime pairs ({a, b}) where (\gcd(a, b) = 1) and (a < b). Note that ({1, 1}) is excluded. When (n = 20), there are exactly 127 ...
Posted on Wed, 13 May 2026 01:48:40 +0000 by Erik-NA