more elegant kmp algorithm
quick sqrt algorithm