GCD & LCM

You've learned GCD and LCM. Now see why these numbers appear everywhere in competitive programming.

47 lessons
143 min
Codeforces: 1000-1400LeetCode: 1300-1600

Lessons

1. Intro

The Goal

2m

2. What GCD Means

Common divisors

3m

3. What LCM Means

Common multiples

3m

4. Naive GCD Method

Listing all divisors

3m

5. The Euclidean Algorithm

Fast GCD computation

3m

6. Euclidean Algorithm - Pseudocode

Implementation pattern

3m

7. Why Euclidean Algorithm Works

The core idea

4m

8. Recursive Version

Shorter code

3m

9. Computing LCM from GCD

The formula

3m

10. Why the LCM Formula Works

Prime factorization view

3m

11. GCD of Multiple Numbers

Extending the algorithm

3m

12. Quiz: GCD Basics

Knowledge check

2m1 problems

13. Problem - Greatest Common Divisor of Strings

LeetCode 1071

2m1 problems

14. GCD of Strings - The Idea

Length relationship

4m

15. GCD of Strings - Algorithm

Two-step check

3m

16. GCD of Strings - Pseudocode

Implementation

3m1 problems

17. Simplifying Fractions

GCD application

3m

18. Clock Synchronization Problem

LCM application

3m

19. Problem - Nth Magical Number

LeetCode 878

2m1 problems

20. Nth Magical Number - Counting Formula

Inclusion-exclusion principle

3m

21. Nth Magical Number - Binary Search

Finding the answer

3m

22. Nth Magical Number - Pseudocode

Implementation

4m1 problems

23. Quiz: LCM and Applications

Knowledge check

2m1 problems

24. Extended Euclidean Algorithm

Finding coefficients

3m

25. Extended Euclidean - How It Works

Backtracking through steps

4m

26. Coprime Numbers

When GCD equals 1

3m

27. GCD Properties

Useful identities

3m

28. Problem - Ugly Number III

LeetCode 1201

2m1 problems

29. Ugly Number III - Inclusion-Exclusion

Counting with three sets

3m

30. Ugly Number III - Binary Search

Finding the answer

4m

31. Ugly Number III - Pseudocode

Implementation

4m1 problems

32. Quiz: Inclusion-Exclusion

Knowledge check

2m1 problems

33. When to Use GCD

Problem patterns

4m

34. When to Use LCM

Problem patterns

3m

35. GCD and Prime Factorization

The connection

3m

36. GCD with Negative Numbers

Absolute values

3m

37. GCD of Arrays

Folding from left

3m

38. LCM of Arrays

Folding and overflow

3m

39. Binary GCD Algorithm

Stein algorithm

4m

40. Practice - Find GCD Sum

LeetCode 1979

3m1 problems

41. Practice - Greatest Common Divisor Traversal

LeetCode 2709

4m1 problems

42. Quiz: Advanced GCD

Knowledge check

2m1 problems

43. Problem - Fraction Addition

Add fractions using GCD

2m1 problems

44. Fraction Addition - Insight

Common denominator approach

4m

45. Fraction Addition - Algorithm

Parse and compute

3m

46. Fraction Addition - Implementation

The pseudocode

5m1 problems

47. Section Recap

What we learned

2m

Ready to start learning?

Access all 47 lessons with interactive content and progress tracking.