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

abcd
aaaa
ababab
.

Sample Output

1
4
3

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.
 
 
prekmp写残了,导致以为EOF不会写,后来才发现Next[j]=-1了。。。。
其实就是求最小循环节,然后循环次数n就最大了。
 
 #include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
using namespace std;
int Next[],n;
char p[]; void prekmp() {
int i,j;
j=Next[]=-;
i=;
while(i<n) {
while(j!=-&&p[i]!=p[j]) j=Next[j];
if(p[++i]==p[++j]) Next[i]=Next[j];
else Next[i]=j;
}
} int main() {
//freopen("in","r",stdin);
while(~scanf("%s",p)) {
if(p[]=='.') break;
n=strlen(p);
prekmp();
int l=n-Next[n];
if(n%l==) printf("%d\n",n/l);
else printf("%d\n",);
}
}

最新文章

  1. centos6.5安装oracle11g_2
  2. map 和 vector 的erase函数说明
  3. grep使用多个查询条件--或
  4. 转: Oracle表空间查询
  5. Spring MVC实现文件下载
  6. Xcode7如何添加pch文件
  7. 错误: 找不到或无法加载主类 / Class not found
  8. Latex调整行距
  9. mob分享
  10. JAVA并发编程实战---第三章:对象的共享(2)
  11. ajaxfileupload批量上传文件+图片尺寸限制
  12. 【伯乐在线】HashMap的工作原理
  13. 【憩园】C#并发编程之异步编程(一)
  14. 浅谈AJAX基本实现流程
  15. MySQL数据库对象-索引
  16. ffmpag总结_android_to_ios视频转换
  17. Mysql更改表名大小写不敏感
  18. CRC8校验
  19. spring AOP 之一:spring AOP功能介绍
  20. srv.exe蠕虫病毒~

热门文章

  1. 跨数据文件删除flashback database
  2. 监控和安全运维 1.5 nagios监控客户端-1
  3. java,js判断全角半角
  4. JS获取页面URL信息
  5. 认识RESTFul
  6. SpringBoot04 日志框架之Logback
  7. Python 网络爬虫 007 (编程) 通过网站地图爬取目标站点的所有网页
  8. php学习笔记-多维数组
  9. ZROI2018提高day3t2
  10. DIY的RPM包怎么签名呢 How to sign your custom RPM package with GPG key