Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 37685   Accepted: 15590

Description

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.

Source

基础题目,只要是理解next函数。

 #include<iostream>
#include<vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <math.h>
#include<algorithm>
#define ll long long
#define eps 1e-8
using namespace std; int nexts[];
char b[]; void pre_nexts(int m)
{
memset(nexts,,sizeof(nexts));
int j = ,k = -;
nexts[] = -;
while(j < m)
{
if(k == - || b[j] == b[k]) nexts[++j] = ++k;
else k = nexts[k];
}
}
int main(void)
{
while(scanf("%s",b),b[] != '.')
{
int n = (int)strlen(b);
pre_nexts(n);
if(n % (n-nexts[n]) == && n/(n - nexts[n]) > ) printf("%d\n",n/(n-nexts[n]));
//根据next函数的最后一个匹配数,算出循环节点~
else printf("1\n");
}
return ;
}

最新文章

  1. BPM业务流程管理与SAP如何更好集成整合?
  2. Oracle 应用于.NET平台
  3. linux下安装编译php的curl扩展
  4. Linux中记录终端(Terminal)输出到文本文件(转载)
  5. VC++中,如何定义callback函数和它的触发事件?
  6. Java按正则提取字符串
  7. 网络资源(5) - Android视频
  8. github上fork了别人的项目后,再同步更新别人的提交
  9. [LeetCode] Decode Ways II 解码方法之二
  10. Day039--HTML
  11. asp:DropDownList 使用
  12. B. Yet Another Array Partitioning Task ——cf
  13. Xeon Phi 《协处理器高性能编程指南》随书代码整理 part 3
  14. 研究VCL源码的原因和起点
  15. 【bzoj3680】平衡点 模拟退火
  16. 相关系数(CORRELATION COEFFICIENTS)会骗人?
  17. cxGrid 颜色设置
  18. Windows下文件检索的基本姿势
  19. Leetcode 240 Search a 2D Matrix II (二分法和分治法解决有序二维数组查找)
  20. PAT 1058 选择题(20)(代码+思路)

热门文章

  1. ArduinoUno和Leonardo的区别
  2. java基础温习 -- 多态
  3. &lt;随便写&gt;佛祖,哈哈!
  4. 通过实体类生成建表SQL语句实现方法
  5. [Swoole系列入门教程 3] 心跳检测
  6. Java开源诊断工具 Arthas 发布v3.1.0
  7. myeclipse 配置svn
  8. spring-cloud服务网关中的Timeout设置
  9. Android App的设计架构:MVC,MVP,MVVM与架构AAAAA
  10. C# 无边框窗体移动和改变大小的实现