(Find the number of circulation sections) Power Strings--POJ--2406

Source: Internet
Author: User
Tags printable characters

Link:

http://poj.org/problem?id=2406

Power StringsTime limit:3000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U SubmitStatus

Description

Given 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 are defined in the normal way:a^0 = "" (The empty string) and a^ (n+1) = A * (a^n).

Input

Each test case was a line of input representing S, a string of printable characters. The length of S'll be is at least 1 and would not exceed 1 million characters. A line containing a period follows the last test case.

Output

For each s should print the largest n such, that s = a^n for some string a.

Sample Input

Abcdaaaaababab.

Sample Output

143

Hint

This problem have huge input, use scanf instead of CIN to avoid time limit exceed. Code:
#include <stdio.h>#include<string.h>#include<stdlib.h>#defineN 1000007CharS[n];intNext[n]; ///Next, the maximum similarity between prefix and suffix is saved.voidFindNext (intSlen,intNext[])///Next[i] represents the maximum match of the first I character{    intI=0, j=-1; next[0] = -1;  while(i<Slen) {        if(j==-1|| s[i]==R[j]) next[++i] = + +J; ElseJ=Next[j]; }}intMain () { while(SCANF ("%s", s), strcmp (S,"."))    {        intslen=strlen (S);        FindNext (Slen, Next); if(slen% (slen-Next[slen])) printf ("1\n"); Elseprintf ("%d\n", slen/(slen-Next[slen])); }    return 0;}
View Code

(Find the number of circulation sections) Power Strings--POJ--2406

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.