fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main
  5. {
  6. public static int stringpow(String s)
  7. {
  8. int answer = 1;
  9. int size = s.length();
  10. for(int i = 1; i < size/2+1; ++i)
  11. {
  12. if (size % i == 0)
  13. {
  14. boolean not_broken = true;
  15. String current = s.substring(0, i);
  16. for(int j = 0; j < size-i; j += i)
  17. {
  18. if (!(current.equals(s.substring(j+i, j+2*i))))
  19. {
  20. not_broken = false;
  21. break;
  22. }
  23. }
  24.  
  25. if (not_broken)
  26. {
  27. answer = size/i;
  28. break;
  29. }
  30. }
  31. }
  32. return answer;
  33. }
  34.  
  35. public static void main (String[] args) throws java.lang.Exception
  36. {
  37. Scanner in = new Scanner(System.in);
  38. PrintWriter out = new PrintWriter(System.out);
  39.  
  40. String S;
  41. while(in.hasNextLine())
  42. {
  43. S = in.nextLine();
  44. out.println(stringpow(S));
  45. }
  46.  
  47. out.flush();
  48. }
  49. }
Success #stdin #stdout 0.12s 29472KB
stdin
BbbbBbbbBbbb
dogdogdog
aaaaaaaa
cstring
stdout
3
3
8
1