HCF and LCM

Type two numbers and watch their prime factor trees grow. Shared primes land in the middle of a Venn picture to give the HCF; all of them give the LCM. Euclid's division steps and the HCF × LCM check are shown too.

Keep it one tap away for everyday use.

Bookmark HCF and LCM?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Two numbers
  2. Factor tree
  3. Venn
  4. HCF and LCM
Nothing is uploadedWorks offline once open

Pick two numbers

Whole numbers from 2 to 100 000.

Factor trees

Each number splits into its smallest prime (circled) and what is left, until only primes remain.

Primes in a Venn picture

Euclid's division algorithm

Divide the bigger number by the smaller, then divide the divisor by the remainder, and repeat until the remainder is 0. The last divisor is the HCF.

Try this

  • Pick two different primes, like 17 and 23. The middle of the Venn is empty: the HCF is 1 and the LCM is the product.
  • Pick a number and one of its multiples, like 12 and 36. Where do all the primes of 12 go?
  • Press + on one number again and again and watch the HCF jump around while the trees regrow.
  • Check that HCF × LCM = first × second for every pair you try. Why does it work? (Every prime is counted once in each.)

Check yourself

Fresh questions every time. Nothing is saved.

What it does

Every whole number bigger than 1 is a product of primes in exactly one way (the fundamental theorem of arithmetic). This page uses that to find the HCF (highest common factor, also called the GCD) and the LCM (lowest common multiple) of two numbers, and lets you see why the method works:

  1. A factor tree for each number splits it into primes.
  2. The primes are sorted into a Venn picture: the primes the two numbers share go in the middle, the rest on each side.
  3. The HCF is the product of the middle. The LCM is the product of everything in the picture.
  4. Euclid’s division algorithm finds the same HCF a second way, by repeated division.
  5. A last line checks that HCF × LCM = the product of the two numbers.

It fits the Class 10 chapter real numbers (the fundamental theorem of arithmetic and HCF and LCM by prime factorisation) and is handy for factors and multiples in earlier classes. Euclid’s division algorithm was dropped from the latest Class 10 book but is still in some state syllabuses and competitive exam books, so it stays here.

For really big numbers, modular arithmetic and the extended Euclid table, use the number theory toolkit. Whole-number patterns also turn up in Pythagorean triples in the pythagoras proof playground playground.

How to use it

  • Type two whole numbers from 2 to 100 000, or use the − and + buttons, or tap a quick example.
  • The trees, the Venn picture, the HCF and LCM lines and Euclid’s table all update at once.
  • When one side of the Venn picture has a lot of primes, it shows them as powers (for example 2⁸) so the picture stays readable.

A worked example

The page starts with 96 and 404.

  • 96 = 2 × 2 × 2 × 2 × 2 × 3 = 2⁵ × 3 and 404 = 2 × 2 × 101 = 2² × 101.
  • They share two 2s, so the middle of the Venn holds 2 and 2, and HCF = 2 × 2 = 4.
  • Left side: 2, 2, 2, 3. Right side: 101. LCM = 2⁵ × 3 × 101 = 9 696.
  • Check: 4 × 9 696 = 38 784 = 96 × 404.
  • Euclid: 404 = 96 × 4 + 20, then 96 = 20 × 4 + 16, then 20 = 16 × 1 + 4, then 16 = 4 × 4 + 0. The last divisor is 4, the same HCF.

Why HCF × LCM = a × b

The product a × b uses every prime of a and every prime of b, so the shared primes in the middle are counted twice (once for each number) and the others once. The HCF takes the shared primes once and the LCM takes everything once, so together they use every prime exactly as often as a × b does. (This only works for two numbers, not three.)

Check yourself

Four fresh questions each time: an HCF, an LCM, an LCM from the HCF and the product, and one step of Euclid’s algorithm. Type the answer, press Check, and open the worked answer if you need it. Nothing is saved.

FAQ

What if the numbers share no prime? Then the middle is empty, the HCF is 1 (the numbers are co-prime) and the LCM is just the product.

Is this from the NCERT book? It covers the same topic with fibub’s own pictures and examples. fibub is not part of NCERT.

Where the numbers come from

  • The fundamental theorem of arithmetic, HCF and LCM from prime factorisation, and Euclid's division algorithm are standard number theory. Wording, pictures and examples are fibub's own.
  • Checked against Python's math.gcd and math.lcm for every pair of numbers up to 300, and against hand-worked examples.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Change log for HCF and LCM

  1. Add #1155 HCF and LCM with factor trees Details on GitHub

Every change to fibub

Related tools

Number theory toolkit #T372 Test whether a huge number is prime, factorise it, find gcd and lcm with the extended Euclid table, work out modular powers and inverses, solve Chinese remainder systems, and expand continued fractions with their convergents. Exact whole-number arithmetic, in your browser. Pythagoras proof playground #L69 Drag a right triangle and watch the squares on its sides add up. Slide through four visual proofs (rearrangement, Bhaskara, similar triangles, Baudhayana) with your own side lengths, and list Pythagorean triples. Squares and cubes #L114 Grow a square out of odd-numbered L-shapes and a cube out of unit cubes. Test any number for being a perfect square or cube from its prime factors, find the smallest number that makes it one, and hunt numbers like 1729 that are a sum of two cubes in two ways. Square root finder #L117 Type a number and find its square root four ways with every step shown: pair up prime factors (with the simplest surd form), subtract odd numbers, estimate between two squares and improve the guess, or use the long division method for decimals. Number systems #L120 Type a whole number and see it written six ways: Indian place value with lakh and crore, Roman numerals, Egyptian signs, Mayan dots and bars, Babylonian wedges, and any base from 2 to 16 with place value blocks. Divisibility tests #L124 Type any whole number and see the divisibility rules for 2 to 11 worked on its digits, with the true remainder alongside. A place value picture shows why the rules for 3, 9 and 11 work, plus digital roots and casting out nines. Kaprekar magic squares #L125 Run Kaprekar's routine on any 4-digit number and watch it land on 6174 (or 495 for 3 digits), with a chart of how many steps every start needs. Then build 3 × 3, 4 × 4 and 5 × 5 magic squares one number at a time. Ratio mixer #L126 Add parts of blue and yellow paint (or syrup and water) to two jars and watch the colours. Equal ratios give exactly the same colour; cross-multiplying tells you which mix is bluer or stronger. Scale a mix up to any batch size and practise with fresh questions. Percentage bar #L127 A bar stands for the whole, split into ten 10% blocks. Drag along it to see 35% of 240 (or any percent of any number) with every step. Then chain two percentage changes and see why going up and down by the same percent never gets you back to the start. Area multiplication #L130 See a product as the area of a rectangle. Split it by place value into easy pieces, or build it from a round number with strips added and taken away, so 103 × 97 becomes 100² − 3² = 9991. Every step is written out, and fresh questions let you practise in your head. Number line zoom #L155 Zoom into the number line ten times at a time to pin down √2, √3, π or any fraction, one decimal digit per zoom, with the check at each step. See why √2 never lands on a mark (irrational) while 3/8 does, and use the decimal detective to find whether p/q stops or repeats, and how long the repeating block is. Algorithm stepper #L168 Watch bubble sort put a list in order, binary search halve a sorted list to find a number, and Euclid's algorithm cut a rectangle into squares to find the HCF. Step forwards and back, count the comparisons, and see how the step counts grow from 8 items to a million.

Also related: Flowchart runner, Irrational √2