Resource · Guide or article
Prime Factors
Covers finding a number's prime factors by repeated division and why the loop can stop at the square root, a common warm-up question.
Reviewed
Open the original: Prime Factors (opens the original site in a new tab)Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
Prime number is a whole number greater than 1 that cannot be made by multiplying other whole numbers. The first few prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19 and so on. If we can make it by multiplying other whole numbers it is a Composite Number. Prime factors are those prime numbers which multiply together to give the original number. For example 39 will have prime factors of 3 and 13 which are also prime numbers. Another example is 15 whose prime factors are 3 and 5.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- Definitions of prime, composite, and prime factors, with 39 and 15 as examples.
- Finding the prime factors: the O(n) division loop and its reduction to O(sqrt(n)).
- Hardy-Ramanujan formula: the typical count of distinct prime factors is about log(log(n)).
How to use it
PrepKit study advice, not a claim made by the source.
Code the sqrt(n) version, factor 360 and a large prime, and say in one sentence why stopping at sqrt(n) is safe.
Scope and limitations
Brief. Images come from Math is Fun and further study points to external pages and a YouTube video. A Simplified Chinese translation is linked.
Access and format
Free English Markdown on GitHub, part of the MIT-licensed trekhleb/javascript-algorithms repository.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/algorithms/math/prime-factors/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.