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");
}
}

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. E20170804-mk

    epic n. 史诗; 叙事诗; 史诗般的作品; estimate vt. 估计,估算; 评价,评论; 估量,估价; Sprint  vi. 冲刺,全速短跑; n. 全速短跑; 速度或活动的突然爆发; ...

  2. sql case when 用法

    sql语言中有没有类似C语言中的switch case的语句?? 没有,用case   when   来代替就行了.            例如,下面的语句显示中文年月         select  ...

  3. 巴什博弈----hdu2147-----较难

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total ...

  4. 安装git,创建本地版本库

    安装 由于我使用的是Ubuntu,因此安装很简单,输入:sudo apt-get install git 如果是其他Linux版本,可以直接通过源码安装.先从Git官网下载源码,然后解压,依次输入:. ...

  5. 51nod 1577 线性基

    思路: http://blog.csdn.net/yxuanwkeith/article/details/53524757 //By SiriusRen #include <bits/stdc+ ...

  6. 查看当前linux版本

    lsb_release -a 如果命令不存在,则yum安装 yum install redhat-lsb

  7. MVC系列学习(九)-DTO的使用

    本次学习用的数据库,如下 1.什么是DTO:DataTransferObject 即数据传输对象,服务端的客户端的通信,自动定义个小的实体类,里面只包含我们需要传输的属性 2.不用DTO会有什么问题 ...

  8. Python学习(一)-在VS上搭建开发环境

    1.到官网下载最新Python 注意:虽然目前大部分应用是Python2写的,但Python3必定会成为以后的主流 不管选择学习哪个,了解pyhton2和pyhton3的差异是必须的 2.安装Pyth ...

  9. 9.Hierarchy Editor

    Hierarchy Editor(层次编辑器) 用于定义3D图层的结构,向Ventuz渲染引擎发出“命令”,并指定命令的发生顺序.通常,每个层次节点都会导致对GPU的一个或多个调用,例如设置材质或渲染 ...

  10. 关于用友 U8-UAP二开的一些事

    这是关于一个刚刚接触用友U8的二次开发的一些小心得. 首先就是用友二开的论坛,http://u8dev.yonyou.com/ 当然这个论坛做得不怎么样,提出了好几个问题,都没有回复的. 以下是关于二 ...