Finding all factors of n in O(sqrt(n)) with a tiny JS function
Quick one for beginners: you never need to test past the square root. Each divisor found below sqrt(n) gives you its pair for free, which is why a simple loop up to Math.sqrt(n) is enough. I built a small reference page around this idea here: factor calculator. Handy when you want to sanity-check homework without doing the loop by hand every time.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in