A12737 | Heidi Learns Hashing (Medium)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 \in \{0,1\}^n$ find out the number of different $k$ ( $0 \leq k < n$ ) such that there exists $x \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 $k$ times. For example, $001 \oplus 111 = 110$ and $\mbox{shift}^3(00010010111000) = 00000010010111$ .
Given a bitstring $y \in \{0,1\}^n$ find out the number of different $k$ ( $0 \leq k < n$ ) such that there exists $x \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 $k$ times. For example, $001 \oplus 111 = 110$ and $\mbox{shift}^3(00010010111000) = 00000010010111$ .
输入格式
The first line contains an integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ), the length of the bitstring $y$ .
The second line contains the bitstring $y$ .
The second line contains the bitstring $y$ .
输出格式
Output a single integer: the number of suitable values of $k$ .
输入输出样例
输入 #1
4 1010
输出 #1
3
输入 #2
16
输出 #2
NO
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 $x$ such that $x \oplus x = 1010$ , hence the answer is $3$ .
- $1100\oplus \mbox{shift}^1(1100) = 1010$
- $1000\oplus \mbox{shift}^2(1000) = 1010$
- $0110\oplus \mbox{shift}^3(0110) = 1010$
There is no $x$ such that $x \oplus x = 1010$ , hence the answer is $3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted