count and index to 0, which represent the number of times s2 is found in str1 and the current index in s2, respectively.indexr and countr of size size(s2) + 1, with all elements set to 0. These arrays will store the index and count at the start of each s1 block.i from 0 to n1 - 1:
a. For each character in s1, increment index if the character matches the current character in s2.
b. If index equals size(s2), reset index to 0 and increment count.
c. Store the current count and index in countr[i] and indexr[i].k from 0 to i - 1:
a. If indexr[k] equals the current index, calculate the counts for the block before repetition (prev_count), the repeating block (pattern_count), and the block after repetition (remain_count).
b. Sum the three counts and return the sum divided by n2.countr[n1 - 1] / n2.