Prime factorisation, GCD and LCM with exact arithmetic
This article explains how the prime factoriser breaks a number down, why it only needs to check divisors up to the square root, how GCD and LCM are computed from two or three numbers at once, and what the divisor count and sum tell you about a number's structure.

What prime factorisation means
Every whole number greater than one can be written as a product of prime numbers in exactly one way. The number 360, for example, is 2 to the third power times 3 squared times 5. No other combination of primes multiplies to give 360. This is called the fundamental theorem of arithmetic, and it is the reason factorisation matters: it is the unique fingerprint of a number.
A prime is a number whose only factors are one and itself. Two, three, five, seven, eleven and so on. One is not prime, and that is not a matter of taste. If one were counted as prime, the factorisation of six would be 2 times 3, or 1 times 2 times 3, or 1 times 1 times 2 times 3, and uniqueness would break. Keeping one out of the club is what makes the theorem work.
The controls on the page
The First number field is the one that gets factorised. Type a whole number and the result appears immediately: its prime factors written out with exponents, the count of distinct primes, the total number of divisors, and the sum of all its divisors.
The Second number and Third number fields are optional. When you fill in a second number, the tool also reports the greatest common divisor and least common multiple of the pair, plus whether they are coprime. A third number extends both calculations across all three. The second field arrives with 48 already in it as a worked example, and the third arrives empty. Clear the second and the GCD and LCM rows disappear, because those rows only show when at least two numbers are present.
Why the square root is the finish line
Trial division works by testing every candidate divisor starting from two. The key insight is that you can stop at the square root of the number. If a factor exists above the square root, it must have a partner below it. The two multiply together to give the original number, and the smaller one would already have been found.
Take 91 as an example. Its square root is about 9.5. Testing 2, 3, 5 and 7, you find that 7 divides 91 to give 13. There is no need to test 11 or 13 individually, because by the time you pass the root you have already caught everything. Whatever is left over after dividing out all the small factors is itself prime.
This turns a search that might test every number up to n into one that only tests up to the square root of n. For a number like a billion, that means checking about 31,000 candidates instead of a billion. The difference between those two is the difference between instant and impossible.
GCD by Euclid's algorithm
The greatest common divisor of two numbers is the largest number that divides both of them evenly. The GCD of 360 and 48 is 24, because 24 goes into both and nothing larger does.
The method used is Euclid's algorithm, which dates to about 300 BC and remains the standard approach. It works by repeated division: divide the larger number by the smaller, take the remainder, and repeat using the smaller number and the remainder. When the remainder reaches zero, the last non-zero value is the GCD. For 360 and 48: 360 divided by 48 leaves 24, then 48 divided by 24 leaves 0, so the GCD is 24.
With three numbers, the same process is applied in sequence. The GCD of the first two is found, and then the GCD of that result with the third number gives the final answer. If the result is one, the numbers are coprime, meaning they share no common factor apart from one.
LCM without overflow
The least common multiple of two numbers is the smallest number that both divide into evenly. For 360 and 48, the LCM is 720.
There is a clean relationship between GCD and LCM: the LCM of a and b equals a divided by the GCD of a and b, multiplied by b. The division comes first on purpose. Multiplying two large numbers and then dividing risks creating an intermediate value too large to store. Dividing first keeps the numbers manageable throughout.
This method also means the LCM can be computed without factorising either number. The GCD comes from Euclid's algorithm, which needs no factorisation at all. That matters for very large numbers where trial division would be slow.
Divisor count, divisor sum and perfect numbers
Once you have the prime factorisation, two useful facts drop out of it for free. The total number of divisors is the product of each exponent plus one. For 360, whose factorisation is two cubed times three squared times five, the divisor count is (3+1) times (2+1) times (1+1), which is 24. That means 360 has 24 different numbers that divide it evenly.
The sum of all divisors is computed from a similar formula. For each prime factor p raised to the power e, the contribution is 1 plus p plus p squared, all the way up to p to the e. Multiply those contributions together and you get the sum of every divisor of the original number.
A perfect number is one where the sum of its proper divisors, meaning all divisors except the number itself, equals the number. Six is the smallest: its divisors are 1, 2 and 3, which add to 6. Only 51 perfect numbers are known, and whether an odd perfect number exists is one of the oldest open problems in mathematics. The tool flags a perfect number when it finds one.
BigInt and why ordinary numbers are not enough
Standard numbers in a web browser lose exact whole-number precision above two to the power of 53, which is roughly nine thousand trillion. Past that point, adding one to a number might not change it at all, because the storage format rounds to fit. A factoriser that silently rounds its input before factorising is worse than useless, because the factors it reports may belong to a different number entirely.
The factorising, the divisor sums and the multiples all use BigInt, a data type that stores whole numbers of any size with perfect accuracy. Nothing rounds once the arithmetic starts. There is one honest limit before that point, though. The three boxes are ordinary number fields, so the browser hands over a plain number, and digits past about the fifteenth are already gone by then. Type 999999999999999989 and the tool sees 1000000000000000000 instead. Stay under about nine thousand trillion and what you type is exactly what gets factorised. The hard cap is a billion billion, and anything above that is refused outright. That ceiling is there because trial division on very large semiprimes, the product of two big primes, gets genuinely slow. The slowness is not a bug. It is the very property that modern encryption depends on.
A worked example with 360 and 48
To see everything in action, enter 360 in the First number field and 48 in the Second number field. The result headline shows the factorisation of 360 as 2 to the third times 3 squared times 5. Three distinct primes are involved. The divisor count is 24, meaning 360 can be divided evenly by 24 different numbers. The divisor sum is 1170.
Below that, the GCD of 360 and 48 appears as 24, and the LCM appears as 720. The coprime test says no, because the two numbers share factors of 2 and 3. Changing 48 to 49 would make them coprime, because 49 is 7 squared and shares nothing with 360.
Try entering 1 on its own. The result says that 1 has no prime factors and is neither prime nor composite. That is correct: it sits outside both categories, and the tool handles the edge case rather than crashing or giving a misleading answer.
Practical uses beyond a maths lesson
These calculations come up more often than you might expect outside a classroom. Simplifying fractions is the most common: the GCD of the top and bottom tells you what to divide both by. Finding a common denominator is the reverse: the LCM of two denominators is the smallest one that works for both fractions.
- Scheduling problems. The LCM of two cycle lengths tells you when two repeating events will line up again. If one machine runs every 12 hours and another every 18, the LCM of 12 and 18 is 36 hours, which is when both cycles land together.
- Checking whether numbers share a factor, which matters in probability, combinatorics and coding theory.
- Puzzle solving, where divisor counts and factor structures are clues in their own right.
- Encryption key checks, where knowing that two values are coprime is a basic requirement.
Everything stays on your machine
The factorisation, GCD and LCM are all computed in your browser. No numbers are sent anywhere. There is no server doing the work, no queue, and no account. The page works just as well offline, because the arithmetic happens entirely on your own device.
That also means there is no practical limit on how many numbers you can try in a session. Each calculation is independent, instant for most inputs, and leaves no trace once you close the tab. For students working through a problem set or a teacher preparing examples, there is no signup wall, no usage cap and no data leaving the room.
