跳到正文

题解

题解:P11909 [NHSPC 2023] H. 整数的回文分解法

five_rice_water约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年3月18日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟
获赞
1
题目
P11909

版本

  1. v1当前

可以说这题主要考察的是比赛经验。

因为这道题的数据范围 nn 相对较大,一般来说对于一个大数,果断打表找规律。

于是就发现了以下规律,第一列的数字枚举的是 nn,第二列的数字是对应的答案。

代码
1 1
2 2
3 2
4 4
5 4
6 8
7 8
8 16
9 16
10 32

或许到这里你已经发现了规律了,对于一个数字 nn,组成的回文序列长度为 2⌊n2⌋2^{\lfloor\frac{n}{2}\rfloor} 次方,但是遗憾的是本蒟蒻不会证明,在此给出快速幂求解的代码,总时间复杂度 O(t×log⁡n)O(t\times\log n),可以通过。

C++
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 105;
const int Mod = 1e9 + 7;
int t, n;

int QuickPower(int x, int k) {
	int ans = 1;
	int base = x;
	while (k) {
		if (k & 1)
			ans *= base, ans %= Mod;
		k >>= 1;
		base *= base, base %= Mod;
	}
	return ans;
}

signed main() {
	cin >> t;
	while (t--) {
		cin >> n;
		cout << QuickPower(2, n / 2) << endl;
	}
	return 0;
}

希望会证明的大佬早日给出证明。

原文