Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).

Input

Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

Output

For each s you should print the largest n such that s = a^n for some string a.

Sample Input

  1. abcd
  2. aaaa
  3. ababab
  4. .

Sample Output

  1. 1
  2. 4
  3. 3

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<vector>
  5. #include<string>
  6. #include<cstring>
  7. using namespace std;
  8. #define MAXN 1000001
  9. typedef long long LL;
  10. /*
  11. 给定一个串,找最短循环节
  12. */
  13. char s[MAXN];
  14. int Next[MAXN];
  15. void kmp_pre(int m)
  16. {
  17. int j,k;
  18. j = ;k = Next[] = -;
  19. while(j<m)
  20. {
  21. if(k==-||s[j]==s[k])
  22. Next[++j] = ++k;
  23. else
  24. k = Next[k];
  25. }
  26. }
  27. int main()
  28. {
  29. while(scanf("%s",s))
  30. {
  31. if(s[]=='.') break;
  32. int l = strlen(s);
  33. kmp_pre(l);
  34. int ans = l - Next[l];
  35. if(l%ans==)
  36. printf("%d\n",l/ans);
  37. else
  38. printf("1\n");
  39. }
  40. }

G - Power Strings的更多相关文章

  1. poj 2406 Power Strings (后缀数组 || KMP)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28859   Accepted: 12045 D ...

  2. poj 2406 Power Strings 后缀数组解法

    连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...

  3. 【poj 2406】Power Strings 后缀数组DC3模板 【连续重复子串】

    Power Strings 题意 给出一个字符串s,求s最多由几个相同的字符串重复而成(最小循环节的重复次数) 思路 之前学习KMP的时候做过. 我的思路是:枚举字符串的长度,对于当前长度k,判断\( ...

  4. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  5. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  6. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  7. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...

  8. E - Power Strings,求最小周期串

    E - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  9. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

随机推荐

  1. HTML--使用下拉列表框,节省空间

    下拉列表在网页中也常会用到,它可以有效的节省网页空间.既可以单选.又可以多选.如下代码: 讲解: 1.value: 2.selected="selected": 设置selecte ...

  2. Dex文件方法数超过65536怎么破?

    你的应用中的Dex 文件方法数超过了最大值65536的上限,会提示你: UNEXPECTED TOP-LEVEL EXCEPTION:java.lang.IllegalArgumentExceptio ...

  3. Django总结二

    - 创建app应用与ORM操作 - Django项目project - app(应用) -> 不同的功能放在不同的app中 - 命令 : - 创建app python manage.py sta ...

  4. BZOJ 3514 LCT+主席树

    思路: //By SiriusRen #include <bits/stdc++.h> using namespace std; ; ],fa[N],minn[N],rev[N],q[N] ...

  5. BZOJ 4140 凸包+二进制分组

    思路: $(x_0-x)^2+(y_0-y)^2<=x^2+y^2$ $y>=(-x_0/y_0)x+(x_0^2+y_0^2)/2y0$ 这显然就是凸包了 以一个斜率不断向下(上)走   ...

  6. 学习c语言的感想

    其实个人认为无论学习什么语言,最重要的是掌握习编程思想,然而C语言一种学习编程思想的基础语言.所以,C语言的重要性不言而喻. 一.课本 无论用的是什么书,要学好C语言,把书上的每一个例题.习题的代码读 ...

  7. wordpress登录账号之后才能查看页面,实例

    函数: <?php auth_redirect(); ?> 例子: 要求用户登录才能查看页面 if(!is_user_logged_in()){ auth_redirect(); } 源文 ...

  8. (转)Vue 爬坑之路(四)—— 与 Vuex 的第一次接触

    在 Vue.js 的项目中,如果项目结构简单, 父子组件之间的数据传递可以使用  props 或者 $emit 等方式 http://www.cnblogs.com/wisewrong/p/62660 ...

  9. Fast-RCNN论文翻译

    http://www.dengfanxin.cn/?p=423 原文地址 本文实现了Fast-RCNN主要部分的翻译工作,在SPPnet出来之后,同在微软的R-CNN的作者Ross迅速怼了回去,抛出了 ...

  10. UIWebview 截获html并修改内容。

    需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果: 方法:通过js截获UIWebView中的html,然后修改html标签内容:  实例代码:  服务 ...