public static long divide_x_y(long x, long y) {
        long res = 0;
        while (x >= y) {
            int power = 1;
            // Checks (y << power) >= (y << (power - 1)) to prevent potential
            // overflow of unsigned.
            while ((y << power) >= (y << (power - 1)) && (y << power) <= x) {
                ++power;
            }

            res += 1L << (power - 1);
            x -= y << (power - 1);
        }
        return res;
    }