Say I make a program that calculates all possible (integral) factors of a certain number that has been input. Is it theoretically more efficient to check with all integers up to the square root of the number or till half of the number.Calculating the square root will take more time and power but will result in fewer divisions and vice-versa for the other option.
What is more efficient, a single square root or multiple divisions?
efficiency;numbers
A square root isn't that long to compute for modern CPUs.  It is better to compute the square root than to continue running your loop up to n/2.  Except maybe for very small n's.There are ways to reduce the cost of square roots:  Precompute the square root:int max = (int)Math.sqrt(n);for(int k=2 ; k <= max ; k++)...or use an integer multiplication in your testfor(int k=2 ; k*k <= n ; k++)...