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. RHEL8/CentOS8的网络IP配置

    rhel8与7的区别 在rhel7上,同时支持network.service和NetworkManager.service(简称NM).默认情况下,这2个服务都有开启,但许多人都会将NM禁用掉. 在r ...

  2. 前端面试:Http协议与浏览器

    Http与Https的区别 Http是明文传输的,Https协议是在Http协议上添加了SSL的加密协议,可以进行加密传输和身份验证. 其实就是说Http对网络传输完全是裸奔状态,也就没办法防范中间人 ...

  3. python模块详解 | progressbar

    参考官方文档:https://pypi.org/project/progressbar/#description progressbar 安装: pip install progressbar pro ...

  4. 【Java】集合综合案例 - 播放器管理

    集合综合案例 文章目录 集合综合案例 需求分析 项目演示 详细设计 代码实现 歌曲类 播放器类 播放列表类 测试 参考资料 播放器管理 需求分析 项目演示 详细设计 代码实现 重新搞一波 复习巩固 简 ...

  5. 【Linux】同时插入多行数据到文本文件中

    如果想同时插入多行数据到指定的文本中,可以用下面的命令EOF cat >> test.txt <<EOF 1234 5678 GOOD EOF 将上述3行插入到 test.tx ...

  6. 使用SimpleUpdater实现现有程序升级功能

    项目:https://github.com/iccfish/FSLib.App.SimpleUpdater C/S程式一般需要部署在多台机器上,如果程式有变动,需要一台一台重新安装,相当麻烦,如果我们 ...

  7. 使用line_profiler对python代码性能进行评估优化

    性能测试的意义 在做完一个python项目之后,我们经常要考虑对软件的性能进行优化.那么我们需要一个软件优化的思路,首先我们需要明确软件本身代码以及函数的瓶颈,最理想的情况就是有这样一个工具,能够将一 ...

  8. 渗透测试中期--漏洞复现--MS08_067

    靶机:Win2k3    10.10.10.130 攻击机:BT5      10.10.10.128 一:nmap 查看WinK3是否开放端口3389 开放3389方法:我的电脑->属性-&g ...

  9. JVM有哪些垃圾回收器

    JVM 的垃圾回收器 目录 JVM 的垃圾回收器 经典垃圾收集器 Serial 收集器 ParNew 收集器 Parallel Scavenge 收集器 Serial Old 收集器 Parallel ...

  10. 前端面试准备笔记之JavaScript(01)

    1.1 typeof 能判断哪些类型? typeof可以识别所有的值类型 typeof可以识别函数 //function typeof可以判断是否是引用类型(不可以再细分) //object 1.2 ...