Write a function to find the root of a number, ensuring you handle edge cases where x < 1 correctly.
Implement root(x) to return the integer square root, meaning the greatest integer r such that r * r <= x. Return 0 for any x < 1. Use an algorithm that avoids floating-point precision issues.
Input: An integer x.
Output: An integer representing floor(sqrt(x)).
def root(x):