This is detected by Floyd's cycle-finding algorithm: two nodes formula_21 and formula_22 (i.e., formula_23 and formula_24) are kept. In each step, one moves to the next node in the sequence and the other moves forward by two nodes. After that, it is checked whether formula_25. If it is not 1, then this implies that there is a repetition in the formula_9 sequence (i.e. formula_27. This works because if the formula_23 is the same as formula_24, the difference between formula_23 and formula_24 is necessarily a multiple of formula_2. Although this always happens eventually, the resulting Greatest common divisor (GCD) is a divisor of formula_3 other than 1. This may be formula_3 itself, since the two sequences might repeat at the same time. In this (uncommon) case the algorithm fails, and can be repeated with a different parameter.