String Theory
Time limit4sMemory limit512 MB
Count substrings of S that equal some nonempty string repeated exactly k times, counting each occurrence position separately.
- Level
Hard9 of 10
- Topics
- String, String matching, Number theory, Math
- Solved
- No attempts yet
Problem
Acesrc is a famous string theorist at Nanjing University, second to none. He insists that an important thing should always be said times. He also believes that every string obtained by concatenating copies of some nonempty string is splendid. So he always teaches newcomers, "String theory problems are important! String theory problems are important! ... String theory problems are important!"
Today he wants to test whether the newcomers remember his instruction. He presents a string of lower case letters and asks them for the number of splendid substrings of the presented string. No one can solve this problem, and they will be scolded for hours. Can you help them solve it?
Note that equal splendid substrings that occur at different positions are counted separately.
Input
The first line of input contains a single integer , the number of test cases. Each test case starts with a line containing an integer . The second line of a test case is a string consisting of lower case letters only, with length between and inclusive. The sum of the lengths of the strings in all test cases never exceeds .
Output
For each test case, print the answer as a single integer on a single line.