Say I have x and want to round it up to the nearest square. How might I do that in a constant time manner?
ie.
$2^2$ is 4 and $3^2$ is 9. So I want a formula whereby f(x) = 9 when x is 5, 6, 7 or 8. What it does when x = 4 or 9 doesn't really matter.
I could write a function to do this easily enough. ie.
while (sqrt(x) is not int) {
x++;
}
But I'd rather not do a brute force approach. Any ideas?
Thanks!