CF1184A2.Heidi Learns Hashing (Medium)

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.

Given a bitstring y∈0,1ny \in {0,1}^n find out the number of different kk (0≤k<n0 \leq k \lt n) such that there exists x∈0,1nx \in {0,1}^n for which y = x \oplus \mbox{shift}^k(x).

In the above, ⊕\oplus is the xor operation and \mbox{shift}^k is the operation of shifting a bitstring cyclically to the right kk times. For example, 001⊕111=110001 \oplus 111 = 110 and \mbox{shift}^3(00010010111000) = 00000010010111.

学习了多项式哈希之后,Heidi 决定学习移位-异或(shift-xor)哈希。特别是,她遇到了这个有趣的问题:

给定一个长度为 nn 的比特串 y∈{0,1}ny \in \{0,1\}^n,求满足如下条件的不同 kk(其中 0≤k<n0 \leq k < n)的个数:存在某个 x∈{0,1}nx \in \{0,1\}^n,使得 y = x \oplus \mbox{shift}^k(x)。

其中,⊕\oplus 表示按位异或(XOR)运算,\mbox{shift}^k 表示将一个比特串循环右移 kk 位的操作。例如,001⊕111=110001 \oplus 111 = 110,且 \mbox{shift}^3(00010010111000) = 00000010010111。

输入格式

The first line contains an integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5), the length of the bitstring yy.

The second line contains the bitstring yy.

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示位串 yy 的长度。

第二行包含位串 yy。

输出格式

Output a single integer: the number of suitable values of kk.

输出一个整数:满足条件的 kk 的个数。

输入输出样例

  • 输入#1

    4
    1010

    输出#1

    3

说明/提示

In the first example:

  • 1100\oplus \mbox{shift}^1(1100) = 1010
  • 1000\oplus \mbox{shift}^2(1000) = 1010
  • 0110\oplus \mbox{shift}^3(0110) = 1010

There is no xx such that x⊕x=1010x \oplus x = 1010, hence the answer is 33.

在第一个例子中:

  • 1100\oplus \mbox{shift}^1(1100) = 1010
  • 1000\oplus \mbox{shift}^2(1000) = 1010
  • 0110\oplus \mbox{shift}^3(0110) = 1010

不存在满足 x⊕x=1010x \oplus x = 1010 的 xx,因此答案为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页