F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Acesrc and String Theory

Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 570    Accepted Submission(s): 221


Problem Description
Acesrc is a famous string theorist at Nanjing University second to none. He insists that we should always say an important thing $k$ times. He also believes that every string that can be obtained by concatenating $k$ 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 examine whether the newcomers remember his instruction. He presents a string consisting of lower case letters and asks them 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 this problem?

Note that equal splendid substrings occurred in different positions should be counted separately.
 

Input
The first line of input consists of a single integer $T$ $(1 \leq T \leq 10)$, denoting the number of test cases. Each test case starts with a single line of an integer $k$ $(1 \leq k \leq 20)$. The second line of a test case is a string $S$ consisting of lower case letters only, the length of which is between $1$ and $3 \times 10^5$ inclusive. The sum of the lengths of strings in all test cases never exceeds $10^6$.
 

Output
For each test case, print the answer as a single integer in a single line.
 

Sample Input
3 2 aabb 2 abababab 3 abc
 

Sample Output
2 6 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-29 12:26:55, Gzip enabled