Theofanis has a string s1s2…sn and a character c. He wants to make all characters of the string equal to c using the minimum number of operations.
In one operation he can choose a number x (1≤x≤n) and for every position i, where i is not divisible by x, replace si with c.
Find the minimum number of operations required to make all the characters equal to c and the x-s that he should use in his operations.
Input
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains the integer n (3≤n≤3⋅105) 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 s of lowercase Latin letters — the initial string.
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
Output
For each test case, firstly print one integer m — the minimum number of operations required to make all the characters equal to c.
Next, print m integers x1,x2,…,xm (1≤xj≤n) — the x-s that should be used in the order they are given.
It can be proved that under given constraints, an answer always exists. If there are multiple answers, print any.
Example
input
Copy
3 4 a aaaa 4 a baaa 4 b bzyx
output
Copy
0 1 2 2 2 3
Note
Let's describe what happens in the third test case:
- x1=2: we choose all positions that are not divisible by 2 and replace them, i. e. bzyx → bzbx;
- x2=3: we choose all positions that are not divisible by 3 and replace them, i. e. bzbx → bbbb.
思路:因为题中说i不能被x整除的,而代替,所以当x=n时,没有i能够被除(n除外),那么只剩第n个元素了,所以n-1不能被n整除,那么也就能将他们全部更新了,这时需要两步,而要最小的步数,那么就要考虑是否有一步和0步的情况了。答案很显然是有的。
一步的情况:它们全在某个数的被数之上,如2,4,6,8等,并且倍数之上的数必须等于c(要么cacbcd,要么acbcdc),否则就有abcbxbzb倍数上是b假如输入的是c,那么改2号位将毫无意义。如果满足条件改第一次出现的位置。
0步的情况:全部相同,并且为c。
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
char a;
cin>>n>>a;
string s;
cin>>s;
bool st=true;
for(int i=0;i<n;i++)
{
if(s[i]!=a)
{
st=false;
}
}
if(st)
{
cout<<"0"<<endl;
}
else
{
for(int i=0;i<n;i++)
{
st=true;
for(int j=i;j<n;j++)
{
st&=(s[j]==a);
j=j+i;
}
if(st)
{
cout<<"1"<<endl<<i+1<<endl;
break;
}
}
if(!st)
{
cout<<"2"<<endl<<n<<" "<<n-1<<endl;
}
}
}
return 0;
}