fork download
  1. import java.util.*;
  2.  
  3. class task6
  4. {
  5. static public int StringPow(final String str)
  6. {
  7. int size = str.length();
  8. int pow = 1;
  9. for (int i=1; i<=size/2; i++)
  10. {
  11. if (size % i != 0)
  12. continue;
  13. String sub1 = new String(str.substring(0, i));
  14. boolean found = true;
  15. for (int j = i; j < size; j+=i)
  16. {
  17. String sub2 = new String(str.substring(j, j+i));
  18. if (!sub1.equals(sub2))
  19. {
  20. found = false;
  21. break;
  22. }
  23. }
  24. if (found)
  25. {
  26. pow = (size/i);
  27. break;
  28. }
  29. }
  30. return pow;
  31. }
  32.  
  33. static public void main (String[] argv)
  34. {
  35. String str;
  36. Scanner in = new Scanner(System.in);
  37. while (in.hasNext())
  38. {
  39. str = in.nextLine();
  40. System.out.println(StringPow(str));
  41. }
  42. in.close();
  43. }
  44. }
Success #stdin #stdout 0.06s 4386816KB
stdin
abcabcabc
aaaaaaaaaa
ollollo
pjpjpjpj
stdout
3
10
1
4