At first you could use a memory cell somewhere to indicate whether the string was found to be the main length or not, and then do more or less what Ness suggested (although I don't quite understand his answer in general).
. 2 , , , . , , . 3 . , . DOES , , . , , , .
, , , . , , , , .
. ( - ), . , .
P.S. Drineas is evil