There's the easy way...Using sets allows for O(1) lookup, optimizing the range-extension algorithm for longer integer sequences.