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 <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int next[1100000] ;
char str[1100000] ;
void getnext(int len)
{
int i=0,j=-1;
next[0]=-1;
while(i<len)
{
if(j==-1||str[i]==str[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
}
int main()
{
int l , m ;
while(scanf("%s", str)!=EOF)
{
if( str[0] == '.' ) break;
l = strlen(str);
getnext(l) ;
m = next[l];
//if(整个串是用循环节组成的),(l-m)为最小循环节
if( l % (l-m) != 0 )//判断最小循环节会被n整除
printf("1\n");
else
{
m = l / ( l-m );
printf("%d\n", m);
}
memset(str,0,sizeof(str));
}
return 0;
}

B - Power Strings的更多相关文章

  1. POJ 2406 Power Strings (KMP)

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

  2. POJ 2406 Power Strings

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

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

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

  4. POJ 2406:Power Strings

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

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

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

  6. poj 2406 Power Strings kmp算法

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

  7. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

  8. 【POJ2406】 Power Strings (KMP)

    Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...

  9. Power Strings

    Power Strings TimeLimit: 1 Second   MemoryLimit: 32 Megabyte Totalsubmit: 1791   Accepted: 528 Descr ...

  10. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

随机推荐

  1. os.system('cmd')在linux和windows系统下返回值的差异

    今天,用os.system('cmd')分别在windows和linux平台上执行同一ping命令,命令执行失败时返回码不同,windows为1,而linux下返回为256,如下: linux下: & ...

  2. 屏蔽每分钟SSH尝试登录超过10次的IP

    屏蔽每分钟SSH尝试登录超过10次的IP 方法1:通过lastb获取登录状态: #!/bin/bash DATE=$(date +"%a %b %e %H:%M") #星期月天时分 ...

  3. DOI技术扫盲一

    DOI:  desktop office intergration   桌面办公软件集成简单的将,就是我们在Windows桌面中打开的办公软件(如:word,excel,pdf等等)可以在SAP系统进 ...

  4. luogu P4116 Qtree3

    题目描述 给出N个点的一棵树(N-1条边),节点有白有黑,初始全为白 有两种操作: 0 i : 改变某点的颜色(原来是黑的变白,原来是白的变黑) 1 v : 询问1到v的路径上的第一个黑点,若无,输出 ...

  5. Django orm中related_name/related_query_name区别

    related_name/related_query_name区别 class Department(models.Model): title = models.CharField(verbose_n ...

  6. 使用 tke-autoscaling-placeholder 实现秒级弹性伸缩

    背景 当 TKE 集群配置了节点池并启用了弹性伸缩,在节点资源不够时可以触发节点的自动扩容 (自动买机器并加入集群),但这个扩容流程需要一定的时间才能完成,在一些流量突高的场景,这个扩容速度可能会显得 ...

  7. windows2012-2016亲测安装mysql8.0

    先去官网下载点击的MySQL的下载 下载完成后解压 解压完是这个样子 不要手动创建Data文件夹和my.ini文件, cmd命令窗口进入bin目录,如果已经做了环境变量那随意在哪里打开. mysqld ...

  8. 在这个应用中,我使用了 MQ 来处理异步流程、Redis 缓存热点数据、MySQL 持久化数据,还有就是在系统中调用另外一个业务系统的接口,对我的应用来说这些都是属于 RPC 调用,而 MQ、MySQL 持久化的数据也会存在于一个分布式文件系统中,他们之间的调用也是需要用 RPC 来完成数据交互的。

    在这个应用中,我使用了 MQ 来处理异步流程.Redis 缓存热点数据.MySQL 持久化数据,还有就是在系统中调用另外一个业务系统的接口,对我的应用来说这些都是属于 RPC 调用,而 MQ.MySQ ...

  9. 网络编程中 TCP 半开连接和TIME_WAIT 学习

    https://blog.csdn.net/chrisnotfound/article/details/80112736 上面的链接就是说明来 SO_KEEPALIVE 选项 为什么还需要 在应用层开 ...

  10. 简单makefile

    https://www.cnblogs.com/prettyshuang/p/5552328.html#_label0