GCD & LCM Calculator

All free toolsAdvanced Mathematics
Advanced MathematicsFree online tool

GCD & LCM Calculator

Calculate the greatest common divisor and least common multiple of a set of integers.

Enter whole numbers. Zero values are allowed; LCM is reported as zero if any input is zero. Exact integer arithmetic is used where supported.

Free online tool by SOCE. Check inputs and results before using them for important decisions.

GCD and LCM Calculator – Free Online GCF, HCF and LCM Guide

The SOCE GCD and LCM Calculator page helps students, teachers, engineers, researchers, and mathematics learners understand the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) through formulas, mathematical methods, and step-by-step worked examples.

GCD and LCM are fundamental concepts in number theory and arithmetic. They are widely used in fraction simplification, divisibility problems, periodic scheduling, numerical algorithms, and mathematical problem-solving.

Whether you are learning prime factorization, the Euclidean algorithm, or the relationship between GCD and LCM, this GCD and LCM Calculator resource provides clear explanations to strengthen your mathematical understanding.

What Is a GCD and LCM Calculator?

A GCD and LCM Calculator is a mathematical tool used to determine two important properties of integers:

  • Greatest Common Divisor (GCD): The largest positive integer that divides each given integer exactly.
  • Least Common Multiple (LCM): The smallest positive integer that is a multiple of each given nonzero integer.

The GCD is also called the Greatest Common Factor (GCF) or Highest Common Factor (HCF).

Simple Example

Consider the numbers:

12 and 18

Their positive common divisors are:

1, 2, 3, and 6

Therefore:

GCD(12, 18) = 6

Their positive common multiples include:

36, 72, 108, …

The smallest is 36.

LCM(12, 18) = 36

These results illustrate the difference between a common divisor and a common multiple.

How to Use the GCD and LCM Calculator

The general calculation process is:

  1. Identify the integers in the problem.
  2. Determine whether the required result is GCD, LCM, or both.
  3. Choose an appropriate mathematical method.
  4. For GCD, identify the greatest common positive divisor.
  5. For LCM, identify the smallest common positive multiple.
  6. Use prime factorization or the Euclidean algorithm where appropriate.
  7. Check the result using divisibility relationships.
  8. Interpret the result in the context of the problem.

For example:

Numbers: 8 and 12

GCD:

GCD(8, 12) = 4

LCM:

LCM(8, 12) = 24

The GCD divides both original numbers, while the LCM is divisible by both original numbers.

GCD and LCM Calculator Formulas

Several mathematical relationships are useful when calculating GCD and LCM.

Greatest Common Divisor Formula

For integers a and b, not both zero:

GCD(a,b) = Greatest positive common divisor of a and b

The GCD is always positive under this convention.

For example:

GCD(24, 36) = 12

because 12 is the largest positive integer that divides both 24 and 36.

Least Common Multiple Formula

For nonzero integers a and b:

LCM(a,b) = |ab| / GCD(a,b)

The absolute value ensures a positive result.

For example:

a = 12

b = 18

GCD = 6

LCM = (12 × 18)/6

LCM = 36

This relationship is one of the most useful identities in elementary number theory.

Product Relationship

For nonzero integers a and b:

GCD(a,b) × LCM(a,b) = |ab|

This formula is useful for checking results and solving problems involving two integers.

GCD and LCM Calculator Using Prime Factorization

Prime factorization expresses a positive integer greater than 1 as a product of prime numbers.

For example:

24 = 2³ × 3

36 = 2² × 3²

Finding the GCD

To calculate the GCD using prime factorization:

  1. Factor each number into prime powers.
  2. Identify prime factors common to both numbers.
  3. Select the smaller exponent for each common prime.
  4. Multiply the selected prime powers.

For 24 and 36:

Common prime factors:

2 and 3

GCD:

2² × 3

= 4 × 3

GCD(24, 36) = 12

Finding the LCM

To calculate the LCM using prime factorization:

  1. Factor each number into prime powers.
  2. Identify all prime factors appearing in either number.
  3. Select the larger exponent for each prime.
  4. Multiply the selected prime powers.

For 24 and 36:

LCM:

2³ × 3²

= 8 × 9

LCM(24, 36) = 72

GCD and LCM Calculator: Step-by-Step Example

Find the GCD and LCM of:

48 and 180

Step 1: Prime Factorization

48 = 2⁴ × 3

180 = 2² × 3² × 5

Step 2: Calculate the GCD

The common prime factors are 2 and 3.

Choose their smaller exponents:

2² × 3

= 4 × 3

GCD = 12

Step 3: Calculate the LCM

Choose the largest exponent of every prime appearing in either factorization:

2⁴ × 3² × 5

= 16 × 9 × 5

LCM = 720

Step 4: Verify the Results

Using the product identity:

GCD × LCM = 12 × 720

= 8,640

Product of the original numbers:

48 × 180 = 8,640

Both sides are equal.

Final Results

Measure Result
First number 48
Second number 180
GCD 12
LCM 720
Product verification 8,640

GCD Calculator Using the Euclidean Algorithm

The Euclidean algorithm is an efficient method for finding the GCD of two integers.

It uses the relationship:

GCD(a,b) = GCD(b, a mod b)

where b is nonzero and “mod” denotes the remainder.

The algorithm continues until the remainder becomes zero.

The last nonzero remainder is the GCD.

Worked Example: GCD of 252 and 105

Divide 252 by 105:

252 = 105 × 2 + 42

Divide 105 by 42:

105 = 42 × 2 + 21

Divide 42 by 21:

42 = 21 × 2 + 0

The last nonzero remainder is 21.

GCD(252,105) = 21

The Euclidean algorithm is especially useful for larger integers because it avoids the need to factor each number into primes.

LCM Calculator Using the GCD Method

Once the GCD is known, the LCM of two nonzero integers can be calculated using:

LCM(a,b) = |ab|/GCD(a,b)

Worked Example

Find the LCM of:

252 and 105

Previously:

GCD(252,105) = 21

Therefore:

LCM = (252 × 105)/21

= 252 × 5

LCM(252,105) = 1,260

Verification:

1,260/252 = 5

1,260/105 = 12

Therefore, 1,260 is a common multiple of both numbers.

GCD and LCM of Three or More Numbers

GCD and LCM can also be calculated for multiple integers.

For three integers a, b, and c:

GCD(a,b,c) = GCD(GCD(a,b),c)

Similarly:

LCM(a,b,c) = LCM(LCM(a,b),c)

The same principle can be extended to additional integers.

Worked Example

Find the GCD and LCM of:

12, 18, and 30

Prime factorization:

12 = 2² × 3

18 = 2 × 3²

30 = 2 × 3 × 5

For GCD, use the smallest common exponents:

2 × 3

GCD(12,18,30) = 6

For LCM, use the largest exponent of every prime:

2² × 3² × 5

= 4 × 9 × 5

LCM(12,18,30) = 180

The two-number product identity should not be applied directly to three or more integers.

Difference Between GCD and LCM

GCD and LCM are related but serve different purposes.

Feature GCD / GCF / HCF LCM
Full name Greatest Common Divisor Least Common Multiple
Meaning Largest positive common divisor Smallest positive common multiple
Prime factorization Smaller common exponents Larger exponents across all primes
Example for 12 and 18 6 36
Typical application Simplifying fractions Finding common periods or denominators

The GCD is associated with divisibility and common factors, while the LCM is associated with common multiples.

GCD and LCM Calculator for Coprime Numbers

Two integers are called coprime or relatively prime when their GCD is 1.

For example:

8 and 15

The positive divisors of 8 are:

1, 2, 4, 8

The positive divisors of 15 are:

1, 3, 5, 15

Their only common positive divisor is 1.

Therefore:

GCD(8,15) = 1

Since the numbers are coprime:

LCM(8,15) = 8 × 15 = 120

Coprime numbers do not need to be prime individually.

For example, both 8 and 15 are composite, but they are coprime.

GCD and LCM Calculator for Fractions

GCD and LCM are useful for fraction simplification and arithmetic.

Simplifying Fractions Using GCD

Consider:

24/36

GCD(24,36) = 12

Divide the numerator and denominator by 12:

24/36 = (24 ÷ 12)/(36 ÷ 12)

24/36 = 2/3

Adding Fractions Using LCM

Consider:

1/6 + 1/8

LCM(6,8) = 24

Convert the fractions:

1/6 = 4/24

1/8 = 3/24

Therefore:

1/6 + 1/8 = 7/24

Answer: 7/24

The LCM provides the least common denominator for these positive integer denominators.

GCD and LCM Calculator for Scheduling Problems

LCM is useful for finding when repeating events occur together.

Worked Example

Suppose two machines complete a cycle every:

12 minutes and 18 minutes.

Both begin their cycles at the same time.

When will they next complete a cycle together?

LCM(12,18) = 36

Answer: After 36 minutes

This assumes the cycle durations are constant and the cycles begin simultaneously.

Another Example

Three independent periodic processes repeat every:

4, 6, and 10 seconds.

Their common repeat period is:

LCM(4,6,10) = 60

Answer: 60 seconds

This principle is useful in periodic scheduling and synchronisation problems.

GCD and LCM Calculator for Engineering Applications

GCD and LCM can support mathematical calculations in engineering, particularly where divisibility, repeated intervals, and integer-based scheduling are relevant.

Construction Planning

LCM can be used to identify common recurrence intervals for periodic activities when their durations are expressed as whole-number time units.

Experimental Scheduling

Repeated laboratory measurements or test cycles can be synchronised using LCM when their intervals are exact integer multiples of a common time unit.

Manufacturing and Production

GCD may help determine the largest common batch or grouping size that divides specified integer quantities exactly.

Computer Science and Algorithms

The Euclidean algorithm is a fundamental method in computational number theory.

LCM is also used in periodic processes, modular arithmetic, and algorithmic scheduling.

Mathematics Education

GCD and LCM are essential for learning fractions, divisibility, prime factorization, and elementary number theory.

GCD and LCM for Zero and Negative Integers

Special cases require careful interpretation.

GCD with Zero

For a nonzero integer a:

GCD(a,0) = |a|

For example:

GCD(18,0) = 18

Under the common mathematical convention:

GCD(0,0) = 0

although some treatments leave this case undefined.

LCM with Zero

Using the common non-negative convention:

LCM(a,0) = 0

for every integer a, including a = 0.

Some elementary definitions restrict LCM to nonzero integers, so calculator behaviour should be checked for zero inputs.

Negative Integers

GCD and LCM are conventionally non-negative.

For example:

GCD(−12,18) = 6

LCM(−12,18) = 36

These conventions help maintain consistent mathematical results.