Reverse Number

You are given an integer NNN and a digit DDD. You have to count the number of pairs AAA and BBB (1≤A,B≤N){(1 \le A, B \le N)}(1≤A,B≤N) such that


This is a companion discussion topic for the original entry at https://toph.co/p/reverse-number