博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2406 Power Strings
阅读量:6929 次
发布时间:2019-06-27

本文共 1345 字,大约阅读时间需要 4 分钟。

Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 39658   Accepted: 16530

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

abcdaaaaababab.

Sample Output

143

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

Source

KMP算法

设字符串的长度为l,假设l%(l-next[l])=0。该序列为循环序列,循环节长度为l-next[l],答案即为l/(l-next[l]);反之则不为循环序列。答案为1。

#include
#include
#include
#include
#include
#include
#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define ll long long#define pa pair
#define maxn 1000010#define inf 1000000000using namespace std;char s[maxn];int l,nxt[maxn];inline void getnext(){ int i=0,j=-1; nxt[0]=-1; while (i

转载地址:http://okvjl.baihongyu.com/

你可能感兴趣的文章
jenkins git maven 自动部署
查看>>
Linux运维不可不知的性能监控和调试工具
查看>>
XAML数据绑定(Data Binding)
查看>>
服务器SSL/TLS快速检测工具TLLSSLed
查看>>
012 出牌显示
查看>>
Zabbix agent自动注册功能实现主机批量监控
查看>>
float display特性介绍
查看>>
多个网卡绑定成一块虚拟网卡
查看>>
phpweb不能成功运行的原因
查看>>
ceph 创建用户,秘钥
查看>>
Valgrind使用
查看>>
马上着手开发iOS应用程序文章总结
查看>>
Lucene学习总结之一:全文检索的基本原理(03-01 - 03-04)好文章,推荐
查看>>
总结:native关键字
查看>>
【顶】辞职也需要辞得帅,辞得大家都开心,多为将来考虑,辞职不要急,本是好事要办好...
查看>>
android singelTask 导致onActivityResult提前执行 mark 一下
查看>>
使用Idea迅速构建一个Spring Boot应用与部署
查看>>
MySQL中decimal类型的小问题
查看>>
仿Fiddler的Chrome插件
查看>>
我的友情链接
查看>>