Add Brent's cycle detection algorithm