3260. Find the Largest Palindrome Divisible by K
3260. Find the Largest Palindrome Divisible by K
Description
You are given two positive integers n and k.
An integer x is called k-palindromic if:
xis a palindrome.xis divisible byk.
Return the largest integer having n digits (as a string) that is k-palindromic .
Note that the integer must not have leading zeros.
Example 1:
1 | Input: n = 3, k = 5 |
Explanation:
595 is the largest k-palindromic integer with 3 digits.
Example 2:
1 | Input: n = 1, k = 4 |
Explanation:
4 and 8 are the only k-palindromic integers with 1 digit.
Example 3:
1 | Input: n = 5, k = 6 |
Constraints:
1 <= n <= 10^51 <= k <= 9
Hints/Notes
- 2024/08/20
- dp
- 0x3Fâs solution(checked)
- Weekly Contest 411
Solution
Language: C++
1 | class Solution { |