digits and divisor. Call a number suitable when its digits can be rearranged into a number that:
- is a palindrome, meaning it reads the same left to right and right to left;
- is divisible by divisor.
Neither the original number nor the rearranged one may start with a zero. For example, with divisor = 2 the number 2020 is suitable (it becomes 2002), while 1010 is not: 0110 starts with a zero and 1001 is odd.
How many suitable numbers have exactly digits digits?digits=2, divisor=3 → 3
The two-digit palindromes are 11, 22, …, 99; of these 33, 66 and 99 are divisible by 3. Their digits cannot be rearranged any other way, so the answer is 3.
digits=1, divisor=1 → 9
Every one-digit number from 1 to 9 is already a palindrome, and all are divisible by 1.
digits=3, divisor=2 → 108
For instance, 112 counts: it becomes 212, which is even. But 110 does not: the only palindrome from its digits is 101, which is odd, and 011 starts with a zero.
digits ≤ 10divisor ≤ 9digits=2, divisor=3
3
Run checks the first 3 tests in your browser. Submit checks all 59 tests on the server, hidden ones included.