Search code examples
mathproof

Why is it required to check for values upto sqrt(n), to determine divisors of a number


I was looking for the most effecient way to determine the divisors of a number. I found an article that mentioned that instead of iterating from 1 upto n, one can reduce the overall running time by iterating from 1 upto sqrt(n), and if suppose 1<=k<=sqrt(n), and k is a divisor of the number n, then another divisor will be n/k.
Is there any mathematical proof why we need to iterate only upto sqrt(n)?


Solution

  • if you have a divisor d >sqrt(n), then its complimentary divisor n/d will be less than n/sqrt(n) which is equal to sqrt(n) so you will have already have found n/d by the end of your algo and therefore also n/(n/d) which is just d.