Problem Statement
John and Brus are studying string theory at the university. Their task is to create a list of all the palindromes that contain between 1 and n lowercase letters ('a'-'z'), inclusive. A palindrome is a string that reads the same forward and backward. Additionally, each palindrome in their list must contain no more than k distinct letters. Return the number of palindromes in the list modulo 1234567891.
Definition
- Class:
- TheLongPalindrome
- Method:
- count
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int count(int n, int k)
- (be sure your method is public)
Constraints
- n will be between 1 and 1,000,000,000, inclusive.
- k will be between 1 and 26, inclusive.
Examples
1
1
Returns: 26
All palindromes in the list are single character strings.
2
10
Returns: 52
Now we have single and double character palindromes.
3
2
Returns: 728
A slightly longer list.
44
7
Returns: 240249781
1000000000
26
Returns: 502499513
999999999
25
Returns: 555594822
23
23
Returns: 1209505107
40
19
Returns: 923760996
39
19
Returns: 1161532321
1000000000
1
Returns: 74074289
757148
26
Returns: 808142191
301413357
26
Returns: 903541512
659598369
26
Returns: 801376963
391749388
26
Returns: 1084608896
35766291
26
Returns: 998485394
473038165
26
Returns: 754312177
3615545
26
Returns: 1134947060
392289611
26
Returns: 854429520
170427799
26
Returns: 1020182844
675016434
26
Returns: 298581589
100757147
19
Returns: 647481233
401413356
23
Returns: 1150834273
759598368
14
Returns: 706606893
491749387
18
Returns: 15745476
135766290
9
Returns: 384108829
573038164
21
Returns: 333945499
103615544
23
Returns: 480834182
1000000000
20
Returns: 198470272
999999999
17
Returns: 517605484
999999999
16
Returns: 652883421
1000000000
20
Returns: 198470272
147
7
Returns: 1126070080
999999999
23
Returns: 1049716493
999999999
11
Returns: 318667120
999999999
26
Returns: 522071800
1000000000
23
Returns: 1232051448
1000000000
25
Returns: 460019892
1000000000
15
Returns: 389687257
1000000000
10
Returns: 482302736
999999973
25
Returns: 1222160695
1000000000
19
Returns: 868920764
574857047
23
Returns: 946932112
999999997
23
Returns: 138511467
51
12
Returns: 776103748