Question Bank

Number Theory Warm-Up

Difficulty: Easy

Short drills on GCD, LCM, modular arithmetic, and modular exponentiation. A gentle on-ramp for interview problems that lean on integer math identities.

Question Bank
/

Number Theory Warm-Up

Number Theory Warm-Up

Short drills on GCD, LCM, modular arithmetic, and modular exponentiation. A gentle on-ramp for interview problems that lean on integer math identities.

Question Bank
Easy
JavaScript
4 questions
number-theory
gcd-lcm
math
quiz

333 views

7

Implement the Euclidean algorithm for gcd(a, b) using only the modulo operator and a loop. Explain why it terminates in O(log min(a, b)) steps.

Examples

Example 1:

Input: a = 48, b = 18
Output: 6
Explanation: gcd(a, b) = gcd(b, a mod b) with gcd(a, 0) = a. Steps: gcd(48, 18) -> gcd(18, 12) -> gcd(12, 6) -> gcd(6, 0) = 6.

Example 2:

Input: a = 100, b = 75
Output: 25
Explanation: gcd(100, 75) -> gcd(75, 25) -> gcd(25, 0) = 25.