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.

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 1000001
typedef long long LL;
/*
给定一个串,找最短循环节
*/
char s[MAXN];
int Next[MAXN];
void kmp_pre(int m)
{
int j,k;
j = ;k = Next[] = -;
while(j<m)
{
if(k==-||s[j]==s[k])
Next[++j] = ++k;
else
k = Next[k];
}
}
int main()
{
while(scanf("%s",s))
{
if(s[]=='.') break;
int l = strlen(s);
kmp_pre(l);
int ans = l - Next[l];
if(l%ans==)
printf("%d\n",l/ans);
else
printf("1\n");
}
}

最新文章

  1. Tomcat7.0安装配置
  2. 配置 Windows 下的 nodejs C++ 模块编译环境
  3. 今天早上刚刚碰到的一个问题oracle数据归档已满,只能进行内部连接,ORA-00257 archiver error. 错误的处理方法
  4. sqlserver 读取xml 字符串方法
  5. Java学习第一天
  6. javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
  7. SMON功能(一):清理临时段
  8. 使用APUE(UNIX高级编程)源代码
  9. &lt;转Tanky Woo&gt; 字典树
  10. Apache服务器安装配置(win版)
  11. zip &amp; tar 压缩文件时排除某个文件夹
  12. 谈谈书本《c#物联网程序设计基础》中的技术瑕疵,如果你将要读本书,请进来看看!
  13. Python总结(一)
  14. 全卷积网络 FCN 详解
  15. Leetcode: The Maze(Unsolved locked problem)
  16. scrapy 快速入门
  17. 【学习总结】 小白CS成长之路
  18. kudu的读取数据流程
  19. Maven &amp; Gradle 如何从中央仓库下载Jar包
  20. Android 下载zip压缩文件并解压

热门文章

  1. Appium + python -yaml配置文件
  2. Windows(7/8/10)搭建kibana 6.x版本(elasticsearch的可视化服务)
  3. Linux 本命令 基本上用到的命令-自己留着用
  4. 【POJ3280/洛谷2890】[Usaco2007 Open Gold]Cheapest Palindrome(动态规划)
  5. 327 Count of Range Sum 区间和计数
  6. 检查阿里云ssl证书到期情况
  7. 浅谈Java中的hashcode方法以及equals方法
  8. C#入门经典 Chapter4 流程控制
  9. mysql自动增长的有关问题,怎么恢复从1开始
  10. vm装xp安装成功后进入不了系统