2020 HDU多校 第一场 04-Distinct Sub-palindromes(思维)

题目链接: 04-Distinct Sub-palindromes

Description

题意:给定n,求长度为n的字符串中包含的不同次回文串的数目的最大值

S is a string of length n. S consists of lowercase English alphabets.

Your task is to count the number of different S with the minimum number of distinct sub-palindromes. Sub-palindrome is a palindromic substring.

Two sub-palindromes u and v are distinct if their lengths are different or for some i (0 ≤ i ≤ length), ui≠vi. For example, string “aaaa” contains only 4 distinct sub-palindromes which are “a”, “aa”, “aaa” and “aaaa”.

Input

The first line contains an integer T (1 ≤ T ≤ 105), denoting the number of test cases.

The only line of each test case contains an integer n (1 ≤ n ≤ 109).

Output

For each test case, output a single line containing the number of different strings with minimum number of distinct sub-palindromes.

Since the answer can be huge, output it modulo 998244353.

Sample Input

2
1
2

Sample Output

26
676

Method

  • n == 1 时, 显然 不同次回文子串数 最大值为 26;
  • n == 2 时,aa, ab 均包含两个 次回文子串,最大值为 262;
  • n == 3 时,有 aaa, aab, aba, abc 这四种次回文串,且均为 3 个, 最大值为 263;
  • n >= 4 时,考虑在 n == 3 的情况上加上一个字符,只需考虑abcd这种情况,回文子串数最少为3,所以最大值 为 26×25×24;

Code

详见注释

#include <iostream>
#include <cstdio>

using namespace std;
#define Max 1e5+5
#define ll long long
#define mod 998244353
template<typename T> T get(T a, T b) { 		//快速幂(可以不用快速幂,连乘即可)
	ll s = 1%mod;
	while (b) {
		if (b%2 == 1) {
			s = (s*a)%mod;
		}
		b /= 2;
		a = (a%mod)*(a%mod)%mod;
	}
	return s;
}
int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		ll sum, n, k=26;
		scanf("%lld", &n);
		if(n <= 3) sum = get(k, n)%mod;		//如果n <= 3, 次回文串的个数为 26^n 
		else sum = 26*25*24%mod;			//如果n > 3,次回文串的个数为 26*25*24 
		printf("%lld\n", sum);
	}
	return 0;
}

蒟蒻一只,欢迎指正

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值