87+ Local Tools Available
100% Browser Execution (No Uploads)
Zero Latency Instant Output
100% Private & Secure
Calculator & Math Client Local

GCD & LCM Calculator

Calculate the GCD and LCM of two or more positive integers in real time. Features arbitrary precision BigInt computation, step-by-step Euclidean algorithm logs, and prime factorization analysis.

100% Client-Side BigInt Arbitrary Precision Engine

INPUT NUMBERS

Enter two or more positive integers separated by commas or spaces.

Greatest Common Divisor (GCD)
-
Highest common integer factor
Least Common Multiple (LCM)
-
Lowest common integer multiple
EUCLIDEAN_ALGORITHM_LOGEuclid O(log N)
Enter numbers to view real-time step-by-step calculations...

Zero Server Data Transmission

All numeric calculations and factorization algorithms run strictly inside your browser memory using native WebAssembly and JavaScript BigInt.

Key Mathematical Rules

  • Greatest Common Divisor (GCD): The largest integer that divides all input numbers without remainder. Used to simplify fractions.
  • Least Common Multiple (LCM): The smallest positive integer divisible by all inputs. Used for finding common denominators.
  • Fundamental identity for two numbers: a × b = GCD(a, b) × LCM(a, b)
  • Coprime (Relatively Prime): Numbers whose GCD is exactly 1 (e.g. 8 & 9, 17 & 23).
Number Theory & Algorithm Reference

The Mathematics of GCD & LCM: From Euclidean Division to Modern Cryptography

The Greatest Common Divisor (GCD) and Least Common Multiple (LCM) are fundamental cornerstones of number theory, spanning from elementary arithmetic to advanced public-key cryptography (RSA).

This guide explores the mechanics of the Euclidean Algorithm, prime factorization principles, and practical computational applications.

Euclidean Division Simulation

Logarithmic O(log(min(a,b))) step-by-step division logging remainder transitions

Prime Factorization Matrix

Deconstructs integers into prime powers, visualizing min/max exponent mappings

Arbitrary-Precision BigInt Math

Handles massive integers without IEEE-754 floating point precision overflow

Example GCD and LCM Calculations for Various Number Pairs

Input NumbersGCDLCMIdentity Check (a × b)Coprime Status
12, 1863612 × 18 = 216 = 6 × 36Common Factor
24, 36, 4812144Multi-number synthesisCommon Factor
17, 23 (Primes)139117 × 23 = 391 = 1 × 391Coprime
1071, 4622123,5621071 × 462 = 494,802 = 21 × 23,562Common Factor
8, 9 (Consecutive)1728 × 9 = 72 = 1 × 72Coprime
100, 250, 50050500Multi-number synthesisCommon Factor

1. Mechanics of the Euclidean Algorithm

The Euclidean Algorithm is based on the principle that the greatest common divisor of two integers aa and bb (a>ba > b) is identical to the greatest common divisor of bb and a(modb)a \pmod b.

GCD(a,b)=GCD(b,a(modb))\text{GCD}(a, b) = \text{GCD}(b, a \pmod b)

Repeating this division until the remainder reaches 00 yields the final non-zero remainder as the GCD.

• Example: Compute GCD(1071,462)\text{GCD}(1071, 462)

Step 1: 1071=462×2+1471071 = 462 \times 2 + 147 \rightarrow GCD(1071,462)=GCD(462,147)\text{GCD}(1071, 462) = \text{GCD}(462, 147)

Step 2: 462=147×3+21462 = 147 \times 3 + 21 \rightarrow GCD(462,147)=GCD(147,21)\text{GCD}(462, 147) = \text{GCD}(147, 21)

Step 3: 147=21×7+0147 = 21 \times 7 + 0 (Remainder is 0)

Result: GCD(1071,462)=21\text{GCD}(1071, 462) = 21.

2. The Fundamental Product Formula Relating GCD and LCM

For any two positive integers aa and bb, the product of the numbers equals the product of their GCD and LCM:

a×b=GCD(a,b)×LCM(a,b)a \times b = \text{GCD}(a, b) \times \text{LCM}(a, b)

Consequently, the LCM can be derived directly with a single arithmetic operation:

LCM(a,b)=a×bGCD(a,b)\text{LCM}(a, b) = \frac{a \times b}{\text{GCD}(a, b)}

Note: This closed-form multiplication identity holds strictly for two numbers. For three or more numbers (a,b,ca, b, c), compute sequentially: LCM(a,b,c)=LCM(LCM(a,b),c)\text{LCM}(a, b, c) = \text{LCM}(\text{LCM}(a, b), c).

3. Prime Factorization Method for GCD and LCM

Decomposing numbers into their canonical prime power representations offers intuitive structural clarity.

24=23×3124 = 2^3 \times 3^1

36=22×3236 = 2^2 \times 3^2

GCD: Take the minimum exponent for each shared prime factor:

GCD=2min(3,2)×3min(1,2)=22×31=12\text{GCD} = 2^{\min(3, 2)} \times 3^{\min(1, 2)} = 2^2 \times 3^1 = 12

LCM: Take the maximum exponent across all prime factors present:

LCM=2max(3,2)×3max(1,2)=23×32=72\text{LCM} = 2^{\max(3, 2)} \times 3^{\max(1, 2)} = 2^3 \times 3^2 = 72

4. Everyday Life Applications of GCD and LCM

Sharing snacks equally with friends without leftovers (GCD): You have 24 apples and 36 oranges. What is the maximum number of friends you can share with equally? GCD(24,36)=12\text{GCD}(24, 36) = 12 friends, each receiving exactly 2 apples and 3 oranges.

Bus and subway synchronized meeting times (LCM): A bus arrives every 8 minutes and a subway train arrives every 12 minutes. If both departed together at 7:00 AM, when will they depart together again? LCM(8,12)=24\text{LCM}(8, 12) = 24 minutes, meaning they depart together at 7:24 AM.

Tiling a rectangular room with largest square tiles (GCD): You want to tile a 180cm by 120cm bathroom floor using identical square tiles without cutting any tile. The largest possible square tile size is GCD(180,120)=60cm\text{GCD}(180, 120) = 60\text{cm}, fitting exactly 6 tiles (3 across × 2 down).

Medication and vitamin schedules (LCM): You take Vitamin A every 6 days and Vitamin B every 8 days. If you took both today, in how many days will you take both on the same day again? In LCM(6,8)=24\text{LCM}(6, 8) = 24 days.

Matching hot dog buns and sausages (LCM): Sausages are sold in packs of 10, and buns in packs of 8. How many hot dogs must you make so no buns or sausages are left over? LCM(10,8)=40\text{LCM}(10, 8) = 40 hot dogs (4 packs of sausages and 5 packs of buns).

5. Key Applications in Computer Science and Programming

Fraction Simplification and Common Denominators: Simplifying 1824\frac{18}{24} requires dividing numerator and denominator by GCD(18,24)=634\text{GCD}(18, 24) = 6 \rightarrow \frac{3}{4}. Finding common denominators for 18+112\frac{1}{8} + \frac{1}{12} requires LCM(8,12)=24\text{LCM}(8, 12) = 24.

Display Aspect Ratio Simplification: Simplifying 1920×10801920 \times 1080 resolution by GCD(1920,1080)=120\text{GCD}(1920, 1080) = 120 derives the canonical 16:916:9 aspect ratio.

Gear Ratio and Cycle Synchronization: Two interlocking gears with 15 and 20 teeth return to starting alignment every LCM(15,20)=60\text{LCM}(15, 20) = 60 tooth passes.

RSA Public-Key Cryptography: Selecting an encryption key ee coprime to Euler totient ϕ(n)\phi(n) is verified via the Extended Euclidean Algorithm.

Cron Batch Task Scheduling: Avoiding simultaneous DB lock contention between background workers with different periods by computing LCM intervals.

6. Characteristics of Coprime Integers

Two integers aa and bb are defined as coprime (relatively prime) if their greatest common divisor is 1: GCD(a,b)=1\text{GCD}(a, b) = 1.

• Any two consecutive integers (n,n+1n, n+1) are always coprime (e.g. 14 & 15).

• Any two distinct prime numbers are coprime (e.g. 13 & 19).

• When aa and bb are coprime, their LCM simplifies to their direct product: LCM(a,b)=a×b\text{LCM}(a, b) = a \times b.

Frequently Asked Questions (FAQ)

Q.Can the Euclidean algorithm compute GCD for 3 or more numbers?
A.Yes. Due to associativity, GCD(a, b, c) = GCD(GCD(a, b), c). Apply the algorithm iteratively across all elements.
Q.How does the calculator handle 0 or negative numbers?
A.GCD and LCM are defined on positive integers. The calculator applies absolute values to negative inputs. GCD(a, 0) = |a|, while GCD(0, 0) is undefined.
Q.Why is the Euclidean algorithm preferred over prime factorization?
A.Integer factorization of large numbers is computationally intractable (NP-hard), whereas the Euclidean algorithm runs in logarithmic time O(log N), computing answers instantly.
Q.How do I know if two numbers are coprime?
A.If their calculated GCD equals 1, the numbers are coprime.