My Solution
```
/**
 * Time Complexity: O(length1 * n1 + n1 * n1)
 * Space Complexity: O(n1)
 * where `length1` is the length of the string `s1`
 */
class Solution {
 public:
  int getMaxRepetitions(const string &s1, const int n1, const string &s2, const int n2) {
    /**
     * the index of the character, which will be visited, of the string `s2`
     */
    int index = 0;
    /**
     * the count of the string `s2` which has been visited
     */
    int count = 0;
    /**
     * `indices[i]` stands for the index of the character, which will be visited, of the string `s2`,
     * when (`i` + 1) `s1`'s have been visited
     */
    int indices[n1];
    memset(indices, 0, sizeof(indices));
    /**
     * `counts[i]` stands for the count of the string `s2` which has been visited
     * when (`i` + 1) `s1`'s have been visited
     */
    int counts[n1];
    memset(counts, 0, sizeof(counts));
    for (int i = 0; i < n1; ++i) {
      for (const char c : s1) {
        if (c == s2[index]) {
          ++index;
          if (index == s2.size()) {
            index = 0;
            ++count;
          }
        }
      }

      for (int j = 0; j < i; ++j) {
        if (indices[j] == index) {
          // find the repetition, the result can be got from it earlier.
          const int remained = n1 - (j + 1);
          const int repetition_range = i - j;
          const int repetition_count = count - counts[j];
          const int total_count = (remained / repetition_range) * repetition_count + counts[j + remained % repetition_range];
          return total_count / n2;
        }
      }

      indices[i] = index;
      counts[i] = count;
    }
    return count / n2;
  }
};
```
['C++']