Anti-hash Test
Time limit1sMemory limit256 MB
Count occurrences of u in the popcount-parity string s(n) of length 2^n, and how many strings v share that occurrence count.
- Level
Hard9 of 10
- Topics
- String matching, Recursion, Math
- Solved
- No attempts yet
Problem
It is well known that the following string can challenge almost every solution that uses polynomial hashes modulo :
where is the number of ones in the binary representation of .
Given a string and an integer , find the number of occurrences of in and the number of distinct strings that have the same number of occurrences in . Both numbers can be very large, so print them modulo .
Input
There are multiple test cases. The first line contains an integer , the number of test cases. Each test case has two lines.
The first line contains an integer ().
The second line contains a string () consisting only of the letters a and b.
The sum of over all test cases does not exceed .
Output
For each test case, if does not appear in , print . Otherwise, print two integers: the number of occurrences of in modulo , and the number of distinct strings with the same number of occurrences in modulo .