可以说这题主要考察的是比赛经验。
因为这道题的数据范围 相对较大,一般来说对于一个大数,果断打表找规律。
于是就发现了以下规律,第一列的数字枚举的是 ,第二列的数字是对应的答案。
1 1
2 2
3 2
4 4
5 4
6 8
7 8
8 16
9 16
10 32或许到这里你已经发现了规律了,对于一个数字 ,组成的回文序列长度为 次方,但是遗憾的是本蒟蒻不会证明,在此给出快速幂求解的代码,总时间复杂度 ,可以通过。
#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;
}希望会证明的大佬早日给出证明。