Math Runs locally Ready to use Built-in examples No tracking

GCF and LCM Calculator

Enter two or more integers to get their greatest common factor and least common multiple, plus a prime factorization for each number.

Simplifying a fraction needs the greatest common factor; adding fractions needs the least common multiple. The same pair of ideas turns up in gear ratios, repeating cycles and tile layouts. Enter two or more integers and both answers come back together with the prime factorisation of every input, so the working can be checked line by line rather than taken on trust.

For two numbers LCM(a, b) = a × b ÷ GCF(a, b) holds exactly; with three or more, apply it pairwise. This tool accepts negative integers but reports the GCF and LCM of their absolute values, following the usual mathematical convention. Factorising very large numbers can take a moment — inputs beyond a sensible range are reported rather than left hanging.

How to use

  1. Enter two or more integers, separated by commas or spaces.
  2. Read the greatest common factor and the least common multiple.
  3. Check the prime factorisation of each input to verify the working.
  4. Copy the results — with more than two numbers the LCM is computed pairwise.

How it works

How to enter the numbers

Separate integers with commas (either width), spaces or newlines — for example 12, 18, 24. At least two numbers are required.

How the greatest common divisor is computed

The GCD is computed pairwise by the Euclidean algorithm: take the GCD of the first two numbers, then combine it with the third, and so on. For example gcd(12,18) = 6, and gcd(6,24) = 6 again.

How the least common multiple is computed

The LCM formula is lcm(a,b) = a × b ÷ gcd(a,b). For several numbers it merges step by step: compute the LCM of the first two, then merge in the next one.

What prime factorization is for

Prime factorization writes each number as a product of prime powers (e.g. 360 = 2³ × 3² × 5). It is also another route to GCD and LCM: the GCD takes the smallest power of every shared prime, the LCM the largest power of every prime that appears.

Code example

JavaScript Euclid's algorithm plus a running LCM

const gcd = (a, b) => b ? gcd(b, a % b) : a;

function gcfLcm(...nums) {
  const g = nums.reduce((a, b) => gcd(a, b));
  const l = nums.reduce((a, b) => a * b / gcd(a, b));
  return { gcf: g, lcm: l };
}

gcfLcm(12, 18, 24);   // { gcf: 6, lcm: 72 }

Python math.gcd and math.lcm

import math
from functools import reduce

math.gcd(12, 18)      # 6
math.lcm(12, 18)      # 36 (Python 3.9+)

# For several numbers:
reduce(math.gcd, [12, 18, 24])   # 6
reduce(math.lcm, [12, 18, 24])   # 72

FAQ

Where are GCD and LCM actually used?

The GCD reduces fractions, splits items into equal groups and simplifies ratios — reducing 12/18 to 2/3 is just dividing by the GCD 6. The LCM unifies denominators and finds when two periodic events coincide: buses every 4 and 6 minutes depart together again after 12 minutes.

Why is the LCM computed from the GCD?

Because a × b always equals gcd(a,b) × lcm(a,b), so lcm(a,b) = a × b ÷ gcd(a,b). Hunting for the LCM by trial division is slow for big numbers; the Euclidean algorithm gets the GCD fast and one division finishes the job — exactly the order this tool uses.

Can I enter negative numbers?

Yes, but results are computed on absolute values. Mathematically gcd(−12, 18) is conventionally the positive 6; this tool follows that convention, taking absolute values automatically while displaying the numbers as you typed them.

What happens when a number is 0?

The LCM involving 0 is 0, since 0 is a multiple of everything. The GCD is unaffected: gcd(0, 5) = 5, because the common divisors of 0 and any number are just that number's divisors.

How many numbers can I enter?

There is no hard limit on the list length, but every number goes through prime factorization, so dozens of numbers in the thousands will slow things down noticeably. Everyday uses — reducing fractions, common denominators — stay within 2 to 5 numbers and compute instantly.

Why is a result sometimes shown as a string of digits?

When the LCM exceeds JavaScript's safe integer range (2^53 − 1, about 9×10^15), the tool outputs an exact digit string instead of risking precision loss through float representation. This typically happens with several large primes near one hundred thousand.

What are the limits of prime factorization?

Only positive integers up to 10^15 are supported, via trial division; larger inputs are reported as too big. Factorizing 1 returns an empty result (1 has no prime factors), and a prime returns itself.

Are my numbers recorded or uploaded?

No. The entire computation runs locally in your browser — the server only serves the page files. History is saved in this browser's localStorage and can be erased with the clear button; incognito windows leave no trace at all.