import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
StringBuilder str = new StringBuilder("");
int cases=Integer.parseInt(br.readLine());
for(int z=0;z<cases;z++) {
if(z>0)
sb.append("\n");
br.readLine();
str = new StringBuilder(br.readLine());
int power = 1;
for (int i = 2; i <str.length()+1; i++) {
if (str.length() % i == 0) {
int period = str.length() / i;
boolean found = true;
for (int j = period; j < str.length(); j++) {
if (str.charAt(j) != str.charAt(j % period)) {
found = false;
break;
}
}
if (found) {
power = Math.max(power, i);
}
}
}
sb.append(str.length()/power).append("\n");
}
System.out.print(sb);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
StringBuilder str = new StringBuilder("");
int cases=Integer.parseInt(br.readLine());
for(int z=0;z<cases;z++) {
if(z>0)
sb.append("\n");
br.readLine();
str = new StringBuilder(br.readLine());
int power = 1;
for (int i = 2; i <str.length()+1; i++) {
if (str.length() % i == 0) {
int period = str.length() / i;
boolean found = true;
for (int j = period; j < str.length(); j++) {
if (str.charAt(j) != str.charAt(j % period)) {
found = false;
break;
}
}
if (found) {
power = Math.max(power, i);
}
}
}
sb.append(str.length()/power).append("\n");
}
System.out.print(sb);
}
}
No comments:
Post a Comment