1 条题解

  • 1
    @ 2023-1-28 18:21:39
    #include <iostream>
    
    using namespace std;
    
    const int N = 1000010;
    
    int n;
    char str[N];
    int Next[N];
    
    void get_next() //KMP算法
    {
        for(int i = 2, j = 0; i <= n; i++)
        {
            while(j && str[i] != str[j + 1]) j = Next[j];
            if(str[i] == str[j + 1]) j++;
            Next[i] = j; 
        }
    }
    
    int main()
    {
        int T = 1;
        while(scanf("%d", &n), n)
        {
            scanf("%s", str + 1);
            get_next();
            
            printf("Test case #%d\n", T++);
            for(int i = 2; i <= n; i++)
            {
                int t = i - Next[i]; //求循环节长度
                if(t != i && i % t == 0) printf("%d %d\n", i, i / t);
            }
            puts("");
        }
        return 0;
    }
    

    100的

    • 1

    信息

    ID
    52
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    递交数
    64
    已通过
    47
    上传者