GCD & LCM Calculator
Calculate the Greatest Common Divisor and Least Common Multiple of multiple numbers.
Separate numbers by commas or spaces
How it works
- GCD (Greatest Common Divisor) is the largest number that divides all input numbers.
- LCM (Least Common Multiple) is the smallest number that all input numbers divide into.
- Uses the Euclidean algorithm for efficient GCD calculation.
About this tool
The Greatest Common Divisor (GCD) and Least Common Multiple (LCM) are fundamental concepts in number theory used throughout mathematics, engineering, and computer science. GCD represents the largest number that divides evenly into a set of integers, while LCM is the smallest number that is divisible by all of them. Whether you are simplifying fractions, solving problems involving ratios, managing periodic cycles, or optimizing algorithms, understanding and calculating GCD and LCM is essential for working efficiently with whole numbers.
To use this calculator, enter two or more integers into the input field, separated by commas or spaces. The tool instantly computes the GCD—the largest common factor of your numbers—and the LCM—the smallest common multiple. These calculations are presented clearly alongside a step-by-step breakdown of the algorithm, helping you understand the underlying logic. The calculator handles any positive integers and works seamlessly with multiple numbers, making it invaluable for students learning number theory, professionals solving real-world problems, and anyone needing quick, reliable divisor and multiple calculations.
Frequently Asked Questions
Code Implementation
import math
def gcd(a: int, b: int) -> int:
"""Euclidean algorithm for Greatest Common Divisor."""
while b:
a, b = b, a % b
return a
def lcm(a: int, b: int) -> int:
"""Least Common Multiple via GCD."""
return abs(a * b) // gcd(a, b)
def gcd_multi(*nums: int) -> int:
"""GCD of multiple numbers."""
result = nums[0]
for n in nums[1:]:
result = gcd(result, n)
return result
def lcm_multi(*nums: int) -> int:
"""LCM of multiple numbers."""
result = nums[0]
for n in nums[1:]:
result = lcm(result, n)
return result
# Examples
print(gcd(48, 18)) # 6
print(lcm(4, 6)) # 12
print(gcd_multi(12, 18, 24)) # 6
print(lcm_multi(4, 6, 10)) # 60
# Using Python's built-in math module (Python 3.9+)
print(math.gcd(48, 18)) # 6
print(math.lcm(4, 6, 10)) # 60Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.