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

kuangbin专题十六 KMP&&扩展KMP POJ2406 Power Strings的更多相关文章

  1. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  5. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  6. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

随机推荐

  1. ajax补充FormData

    一.回顾上节知识点 1.什么是json字符串? 轻量级的数据交换格式 2.定时器:关于setTimeout setTimeout(foo,3000)  # 3000表示3秒,foo表示一个函数,3秒后 ...

  2. 问题:asp.net 点击button按钮调到页面顶部;结果:asp.net点击一个按钮,使页面跳转到本面页上的指定位置

    asp.net点击一个按钮,使页面跳转到本面页上的指定位置 (2011-04-19 16:46:51) 转载▼ 标签: it   最近在做一个项目. 用到标题所说的功能. 实现方法: 1.在aspx中 ...

  3. XSS的各种用途

    0x01 最常见之窃取用户cookie 当cookie没有设置HttpOnly属性时,可以通过javascript代码创建img,script,iframe等标签,并把src属性设置为自己部署的xss ...

  4. Shell编程进阶 1.7 case选择

    逻辑判断的格式 vim case.sh #!/bin/bash read -p "please input a number:" n m=$[$n%] case $m in ) e ...

  5. 部署和调优 1.6 vsftp部署和优化-2

    映射个虚拟用户 创建个用户,不让他登录 useradd virftp -s /sbin/nologin 创建存放虚拟用户用户和密码的文件 vim /etc/vsftpd/vsftpd_login 写入 ...

  6. Windows10更新后无限重启

    以安全模式进入系统,禁用或卸载显卡驱动. 重启后重新安装驱动.

  7. windows下单机版的伪分布式solrCloud环境搭建Tomcat+solr+zookeeper

    原文出自:http://sbp810050504.blog.51cto.com/2799422/1408322           按照该方法,伪分布式solr部署成功                 ...

  8. day17-jdbc 7.Statement介绍

    SQL语句:DML.DQL.DCL.DDL.DML和DQL是用的最多的.DCL和DDL用的很少. 程序员一般是操作记录,创建一表很少. package cn.itcast.jdbc; import c ...

  9. Ros学习——Python发布器publisher和订阅器subscriber

    1.编写发布器 初始化 ROS 系统 在 ROS 网络内广播我们将要在 chatter 话题上发布 std_msgs/String 类型的消息 以每秒 10 次的频率在 chatter 上发布消息 在 ...

  10. koa的跨域访问

    koa跨域访问:1.安装插件 npm install koa-cors --save-dev2.项目的app.js中var cors = require('koa-cors'); app.use(co ...