跳到正文

题解

题解:P12197 Hash Killer I

WorldMachine约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年4月16日
收录
2025年12月12日
更新
2026年8月22日
篇幅
约 2 分钟
获赞
40
题目
P12197

版本

  1. v1当前

我赌他没卡我的自然溢出。

对于 bb 为偶数的情况,只要串够长 bnb^n 就变成 00 了。

对于奇数的情况,Thue Morse 序列可以让它爆炸。

对于二进制串 ss,定义 sˉ\bar s 为按位翻转后的串。令 00 阶 Thue Morse 序列 t0=0t_0=\texttt{0},tn=tn−1+tn−1‾t_n=t_{n-1}+\overline{t_{n-1}},有 hash(tn)=b2n−1hash(tn−1)+hash(tn−1‾)\text{hash}(t_n)=b^{2^{n-1}}\text{hash}(t_{n-1})+\text{hash}(\overline{t_{n-1}}),hash(tn‾)=b2n−1hash(tn−1‾)+hash(tn−1)\text{hash}(\overline{t_n})=b^{2^{n-1}}\text{hash}(\overline{t_{n-1}})+\text{hash}(t_{n-1}),记 hn=hash(tn)−hash(tn‾)h_n=\text{hash}(t_n)-\text{hash}(\overline{t_n}),有 hn=(b2n−1−1)hn−1h_n=(b^{2^{n-1}}-1)h_{n-1}。

由于 b2n−1−1=(b−1)(b2n−2+1)(b2n−3+1)…(b+1)b^{2^{n-1}}-1=(b-1)(b^{2^{n-2}}+1)(b^{2^{n-3}}+1)\dots(b+1),而 bb 是奇数,那么每一项都是偶数,故 2n∣b2n−1−12^n|b^{2^{n-1}}-1,那么 2n(n+1)2∣fn2^{\frac{n(n+1)}{2}}|f_n,对于 n≥11n\ge11,n(n+1)2>64\dfrac{n(n+1)}{2}>64,自然溢出就爆炸了。

那么输出长度为 2112^{11} 的 Thue Morse 序列即可。

C++
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n = 1 << 11, l = n >> 1;
	printf("%d %d\n", n, l);
	for (int i = 0; i < n; i++) putchar('a' + (__builtin_popcount(i) & 1));
}
原文
存档评论2 条抓取于