当前位置: 首页 > news >正文

题解:P15790 「10OI R1」相思若循

同步发布于 here。

不知道打表找规律能不能过。

注意,这是一篇打表找规律猜结论的题解,如果你想看严谨证明请移步别的题解。

神秘诈骗题。

题意

多次询问。

每次给定一个长为 \(2^n-1\) 的环,环上第 \(i\) 个数为 \(i\)

现在将每个数与当前这个状态的下一个数求异或,问循环节的最小长度 \(\mod 998244353\) 的结果。

令询问次数为 \(t\),则 \(n \le 10^9,t \le 5 \times 10^5\)

思路

其实没思路。

以下定义 \(\bigoplus\) 为异或符号。

考虑到异或是具有自反性的,也就是 \(a \bigoplus a = 0\),所以形成一个环一定是通过自反性得来的。

然后我们又需要知道,对于一个数 \(x\),其也可以由 \((\bigoplus_{i=1}^{2^n-1} i) \oplus x\) 得到,其中需要满足的是 \(n \ge 2\),这是因为异或的经典结论,即:

\[\bigoplus_{i}^n i = \begin{cases} n & (n\equiv 0 \pmod 4) \\ 1 & (n \equiv 1 \pmod 4) \\ n + 1 & (n\equiv 2\pmod 4) \\ 0 & (n \equiv 3 \pmod 4) \end{cases} \]

\(n \ge 2\) 时,\(\bigoplus_{i=1}^{2^n-1} i = 0\),因为 \(2^n-1 \equiv 3 \pmod 4\)
那我们也就能看成 \(\bigoplus_{i=1,i \neq x}^{2^n-1} i = x\)

我当时并没有想到后面怎么推,于是我想到了手动模拟找规律。

我们先来看样例对于 \(n=2\) 时候的模拟情况。

原数:\(1,2,3\),那么有以下转化。

\[1,2,3 \\ 1 \oplus 2,2 \oplus 3,3 \oplus 1 \\ 1 \oplus 3,2 \oplus 1,3 \oplus 2 \\ 2 \oplus 3,1 \oplus 3,1 \oplus 2 \]

最后一步正好是我们上面说的 \(\bigoplus_{i=1,i \neq x}^{2^n-1} i = x\)

此时循环节长度为 \(3\)

再看看 \(n=3\)

原数即 \(1,2,3,4,5,6,7\),则有:

\[1,2,3,4,5,6,7 \\ 1 \oplus 2,2 \oplus 3,3 \oplus 4,4 \oplus 5,5 \oplus 6,6 \oplus 7,7 \oplus 1 \\ 1 \oplus 3,2 \oplus 4,3 \oplus 5,4 \oplus 6,5 \oplus 7,6 \oplus 1,7 \oplus 2 \\ 1 \oplus 2 \oplus 3 \oplus 4,2 \oplus 3 \oplus 4 \oplus 5,3 \oplus 4 \oplus 5 \oplus 6,4 \oplus 5 \oplus 6 \oplus 7,5 \oplus 6 \oplus 7 \oplus 1,6 \oplus 7 \oplus 1 \oplus 2,7 \oplus 1 \oplus 2 \oplus 3 \\ 1 \oplus 5,2 \oplus 6,3 \oplus 7,4 \oplus 1,5 \oplus 2,6 \oplus 3,7 \oplus 4 \\ 1 \oplus 2 \oplus 5 \oplus 6,2 \oplus 3 \oplus 6 \oplus 7,3 \oplus 4 \oplus 7 \oplus 1,4 \oplus 5 \oplus 1 \oplus 2,5 \oplus 6 \oplus 2 \oplus 3,6 \oplus 7 \oplus 3 \oplus 4,7 \oplus 1 \oplus 4 \oplus 5 \\ 1 \oplus 3 \oplus 5 \oplus 7,2 \oplus 4 \oplus 6 \oplus 1,3 \oplus 5 \oplus 7 \oplus 2,4 \oplus 6 \oplus 1 \oplus 3,5 \oplus 2 \oplus 7 \oplus 4,6 \oplus 3 \oplus 1 \oplus 5,7 \oplus 4 \oplus 2 \oplus 6 \]

可以发现再来一步我们就能凑成 \(\bigoplus_{i=1,i \neq x}^{2^n-1} i = x\) 的形式了,太长了就不写了。

这个循环节长度为 \(7\)

可以发现什么?对于 \(n = 2,n = 3\) 时的循环节长度为 \(2^n-1\),所以我们大胆猜测对于 \(n \ge 2\) 其循环节长度为 \(2^n - 1\),写出代码取模来发现样例确实如此。

\(n=1\) 特判即可。

using ll = long long;
constexpr int mod = 998244353;
ll t, n, m;
ll qpow(ll x, ll y)
{ll res = 1;while(y){if(y & 1) res *= x, res %= mod;x *= x;x %= mod;y >>= 1;}return res;
}
int main()
{ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);cin >> t;while(t --){cin >> n;if(n == 1) cout << "NO\n";else cout << (qpow(2, n) - 1 + mod) % mod << '\n';//这个我是怕取模后 - 1 小于 0 了}return 0;
}
http://www.jsqmd.com/news/925015/

相关文章:

  • 开源 AI Agent Harness Engineering 框架横向对比评测
  • 如何从零构建高仿12306系统:SpringBoot3+Java17分布式架构实战指南
  • 应用安全 --- IDAPro脚本 之 导出函数引用数据
  • 【C++】零基础入门 · 第 14 节:智能指针(unique_ptr、shared_ptr、weak_ptr)
  • 密钥轮换失效、设备绑定丢失、会话劫持频发——Gemini企业级身份验证故障全解析,一线SRE连夜修复的3个致命配置
  • 2026年GEO系统源码公司权威评测:源头厂商与贴牌避坑指南 - 品牌报告
  • 20252806 2025-2026-2 《网络攻防实践》第十周作业
  • 郑州市 惠济区 上门安装、维修维保|维小达 开关插座/灯具/门窗/柜体/锁具/卫浴/龙头/洗菜盆/踢脚线一站式家装安装服务 - 维小达科技
  • 论文反复修改到心累?资深导师力荐这几个AI论文平台
  • 照着用就行:2026年实打实好用的专业降AIGC软件
  • TypeError: Autotuner.__init__() takes from 6 to 9 positional arguments but 14 were given
  • 芜湖黄金店哪家价格最划算? - 鸿运名品
  • AI Agent Harness Engineering 任务优先级排序算法:让智能体学会高效时间管理
  • Keyviz:5分钟学会实时键鼠可视化,让你的操作透明化
  • 基于Arduino与NRF24L01的乐高坦克遥控系统全解析
  • 算术平均值与几何平均值 - ace-
  • Windows端口被占?除了netstat,你还可以试试这些更强大的工具(附PowerShell终极方案)
  • P13981 数列分块入门 6
  • DIY电动背部按摩器:用直流减速电机与偏心轮原理自制放松神器
  • Arduino互动南瓜:超声波传感器与伺服电机的创意制作
  • 实测过的AI提示词方法论和新赛道总结
  • 别再只用history()了!用get_fundamentals()给你的量化策略加点‘基本面’佐料
  • 别再折腾驱动了!用DKMS一劳永逸解决Ubuntu内核升级后的RTL8822CE网卡失效问题
  • Visuino图形化编程实现Arduino舵机交互控制:从按钮到PWM的实践指南
  • 02 基础语法 JavaScript 入门到精通全套教程 19-33
  • 2026西安黄金回收上门服务榜单丨告别出门排队 当面验金秒到账全指南 - 西安闲转记
  • 基于Arduino与LM741的心电图采集系统:从模拟电路到心率检测
  • CAXA 块
  • 6款主流降AIGC网站 降痕效果拉满
  • AI Agent Harness Engineering 在制造:巡检、质检与工艺优化