My prof gave an alternative explanation for checking till sqrt(n) by replying this:
“We need to check for divisors only till max2 ≤ i ≤ n(min(i, n/i)).
The maximum is attained when i = n/i, ie. i = sqrt n.”
What does he even mean? Can someone put it in English?
Formatting the TeX for you, that’s “max2 <= i <= n(min(i, n/i))”. In English, the largest value of the smaller of
iandn/iover all values ofifrom 2 up ton.For example, if
nis 12:It’s quite easy to see that
i < n/iif and only ifi < sqrt(n), and from that we can see that the largest value of that expression will besqrt(n).Presumably, this is for finding the factors of
n. Ifiis a factor, thenn/ialso is, sincen/i * i = n, so there’s no need to test bothiandn/i. Therefore, we can choose only to check the smaller of the two,min(i, n/i), and only need consider values ofiup to the largest such value – which is the value of the expression your teacher gave you.