Given a string $S$ and $q$ queries of the form $l,r$, find the length of the shortest string that, when repeated some number of times, exactly forms the substring $S[l…r]$.
Input:
8
aaabcabc
3
1 3
3 8
4 8
Output:
1
3
5
Explanation:
a
three times results in the string aaa
.abc
two times results in the string abcabc
.abcab
one time results in the string abcab
.String occurences 2 | |
Repeated string | |
Compare substring | |
Palindrome substring 2 | |
String combinations | |
Frequent substring | |
Good pairs | |
String rotation | |
Bit reversing | |
Repeated string 2 |