Nearly Shortest Repeating Substring
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
给你一个长度为 的字符串 ,它由小写字母组成。求最短字符串 的长度,使得多个(可能是一个) 可以连接在一起,形成一个长度与 相同的字符串,且最多只有一个不同的字符。
更正式地说,求最短字符串 的长度,使得 $c = \underbrace{k + \cdots + k}_{x\rm\ \text{times}}$ 为某个正整数 ,字符串 和 的长度相同,且 中最多有一个 (即存在 或 这样的位置)。
输入格式
The first line contains a single integer ( ) — the number of test cases.
The first line of each test case contains a single integer ( ) — the length of string .
The second line of each test case contains the string , consisting of lowercase Latin characters.
The sum of over all test cases does not exceed .
样例 #1
样例输入 #1
5
4
abaa
4
abba
13
slavicgslavic
8
hshahaha
20
stormflamestornflame
样例输出 #1
1
4
13
2
10