| Contests - ACM Student Chapter - PSUT |
|---|
| Private |
| Spectator |
| PSUT Programming Contest 2026 |
|---|
| Finished |
Rayo loves strings, but he dislikes unique substrings. Kilani decided to give him a challenge involving both.
You are given a string $$$s$$$ of length $$$n$$$ and an integer $$$m$$$.
Construct a new string $$$t$$$ of length $$$m$$$ as follows:
For each index $$$i$$$ ($$$1 \le i \le m$$$):
$$$$$$ t[i] = \begin{cases} s[i], & \text{if } i \le n, \\ s[i - n], & \text{otherwise}. \end{cases} $$$$$$
In other words, after copying the first $$$n$$$ characters from $$$s$$$, the string continues by repeating the same pattern every $$$n$$$ characters.
Your task is to determine the number of distinct (unique) substrings of the string $$$t$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^2$$$.
For each test case, print a single integer — the number of distinct substrings of the constructed string $$$t$$$.
22 3ah3 5aaa
55
In the first sample case, the constructed string is aha.
It has 5 distinct sub strings which are: [a, ah, aha, ha, h].
In the second sample case, the constructed string is aaaaa.
It has 5 distinct sub strings which are: [a, aa, aaa, aaaa, aaaaa].
| Name |
|---|

