Codeforces Round #747 (Div. 2)C. Make Them Equal

题目要求将字符串s的所有字符变为字符c,通过选择一个数x,将所有不是x倍数的位置上的字符替换为c。求达到目标的最小操作数及对应的x值。对于每个测试用例,给出了字符串长度n和目标字符c,以及初始字符串s。当n为3到300000之间,所有n之和不超过300000。解答中指出,答案总是存在的,并给出了示例和解题思路。
摘要由CSDN通过智能技术生成

Theofanis has a string s1s2…sn and a character c. He wants to make all characters of the string equal to cc using the minimum number of operations.

In one operation he can choose a number xx (1≤x≤n) and for every position i, where i is not divisible by x, replace sisi with c.

Find the minimum number of operations required to make all the characters equal to cc and the xx-s that he should use in his operations.

Input

The first line contains a single integer tt (1≤t≤104) — the number of test cases.

The first line of each test case contains the integer nn (3≤n≤3⋅10^5) and a lowercase Latin letter c — the length of the string s and the character the resulting string should consist of.

The second line of each test case contains a string ss of lowercase Latin letters — the initial string.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅10^5.

Output

For each test case, firstly print one intege

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值