<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[12pt,reqno]{article}

\usepackage[usenames]{color}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{graphicx}

\usepackage[colorlinks=true,
linkcolor=webgreen,
filecolor=webbrown,
citecolor=webgreen]{hyperref}

\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}

\usepackage{color}
\usepackage{fullpage}
\usepackage{float}

\usepackage{psfig}
\usepackage{graphics}
\usepackage{latexsym}
\usepackage{epsf}
\usepackage{breakurl}

\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{.1in}
\setlength{\evensidemargin}{.1in}
\setlength{\topmargin}{-.1in}
\setlength{\textheight}{8.4in}

\newcommand{\seqnum}[1]{\href{https://oeis.org/#1}{\rm \underline{#1}}}

\begin{document}

\begin{center}
\epsfxsize=4in
\leavevmode\epsffile{logo129.eps}
\end{center}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{problem}[theorem]{Problem}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\def\modd#1#2{#1\ \mbox{\rm (mod}\ #2\mbox{\rm )}}

\begin{center}
		\vskip 1cm{\Large\bf 
			Exact Formulas for the Number of Palindromes in  \\
			\vskip .1in
			Certain Arithmetic Progressions
		}
		\vskip 1cm
		
		\begin{minipage}[t]{0.45\textwidth}
			\begin{center}
				Kritkhajohn Onphaeng\\
				Faculty of Science and Technology \\ Princess of Naradhiwas University\\ Naratiwat 96000 \\
				Thailand \\
				\href{mailto: kritkhajohn.o@pnu.ac.th }{\tt kritkhajohn.o@pnu.ac.th},
				\href{mailto: dome3579@gmail.com }{\tt dome3579@gmail.com}\\
				\ \\
				\ \\
				\ \\
				Phakhinkon Napp Phunphayap\textsuperscript{*}\\
				Department of Mathematics\\
				Faculty of Science\\ 
				Burapha University\\
				Chonburi 20131\\ 
				Thailand\\
				\href{mailto: phakhinkon.ph@go.buu.ac.th }{\tt phakhinkon.ph@go.buu.ac.th},
				\href{mailto: phakhinkon@gmail.com }{\tt phakhinkon@gmail.com}\\
			\end{center}
		\end{minipage}
		\begin{minipage}[t]{0.45\textwidth}
			\begin{center}
				Tammatada Khemaratchatakumthorn \\
				Department of Mathematics \\
				Faculty of Science\\
				Silpakorn University\\
				Nakhon Pathom 73000 \\
				Thailand\\
				\href{mailto: tammatada@gmail.com}{\tt tammatada@gmail.com},
				\href{mailto: khemaratchataku.t@silpakorn.edu}{\tt khemaratchataku.t@silpakorn.edu}\\
				\ \\
				Prapanpong Pongsriiam \\
				Department of Mathematics \\
				Faculty of Science\\
				Silpakorn University\\
				Nakhon Pathom 73000 \\
				Thailand\\
				and\\
				Graduate School of Mathematics \\
				Nagoya University\\
				Nagoya 464-8602\\
				Japan\\
				\href{mailto:prapanpong@gmail.com}{\tt prapanpong@gmail.com},
				\href{mailto:pongsriiam_p@silpakorn.edu}{\tt pongsriiam\_p@silpakorn.edu}\\
			\end{center}
		\end{minipage}
		\let\thefootnote\relax\footnote{\textsuperscript{*}Phakhinkon Napp Phunphayap is the corresponding author.}
		
		
	\end{center}
	
	\vskip .2 in
	
	\begin{abstract}
		A positive integer $n$ is a $b$-adic palindrome if the representation of $n$ in base $b$ reads the same backward as forward.
		In this article, we obtain exact formulas for the number of $b$-adic palindromes that are less than or equal to $m$ and are congruent to $r$ modulo $q$ when $b$ is congruent to $0$ or $1$ mod $q$. 
		This extends Pongsriiam and Subwattanachai's result (done only for $q \leq 2$), and supplements Col's theorem, which is restricted to the case that $b(b^2 - 1)$ is coprime to $q$.
	\end{abstract}

	
		\section{Introduction}
	Let $b \geq 2$, $m,n,q \geq 1$, and $0\leq r &lt; q$ be integers. We call $n$ a \textit{palindrome in base $b$} (or \textit{$b$-adic palindrome}) if the $b$-adic expansion of $n=(a_k a_{k-1}\cdots a_0)_b$ with $a_k\neq 0$ has the symmetric property $a_{k-i}=a_i$ for $0\leq i \leq k$.
	We let $P_b$ be the set of all $b$-adic palindromes and $P_b (m)$ the set of all $b$-adic palindromes not exceeding $m$.  
	The $2$-adic and $10$-adic palindromes are, respectively, \seqnum{A006995} and \seqnum{A002113} in OEIS \cite{S}.
	As usual, if we write a number without specifying the base, then it is always in base 10, and if we write $n = (a_k a_{k-1} \cdots a_0)_b$, then it means that $n = \sum_{i = 0}^k a_i b^{i}$, $a_k \neq 0$, and $0 \leq a_i &lt; b$ for all $i = 0,1,\ldots ,k$. So, for example, $9 = (1001)_2 = (100)_3$ is a palindrome in bases 2 and 10 but not in base 3.
	In addition, let $P_b (m,q,r)$ be the set of all $b$-adic palindromes 
	that are at most $m$ and are congruent to $r$ modulo $q$. 
	Finally, let $A_{b} (m) = | P_b (m) |$ and $A_b (m,q,r) = | P_{b} (m,q,r) |$, that is,
	\begin{equation*}
		A_b (m, q, r) = \sum_{\substack{n \in P_{b} (m) \\ \text{$n \equiv \modd{r}{q}$}}} 1.
	\end{equation*}
	
	In recent years, there has been an increasing interest in the study of palindromes.
	For instance, in 2017, Vepir \cite{Vepir} asked on Mathematics Stack Exchange which number base contains the most palindromic numbers.
	Pongsriiam and Subwattanachai \cite{PS} started the investigation by determining an exact formula for $A_{b} (m)$, but the formula is not easy to analyze, and so it is not enough to answer Vepir's question. 
	After that, Phunphayap and Pongsriiam \cite{PP} showed that if $b_1 &gt; b_2 \geq 2$ and $s_b$ denotes the reciprocal sum of all $b$-adic palindromes, then $s_{b_1}$ and $s_{b_2}$ converge and $s_{b_1} &gt; s_{b_2}$. 
	Later, they also applied Pongsriiam and Subwattanachai's exact formula \cite{PS} to answer Vepir's question that in fact, $A_{b} (n) - A_{b_1} (n)$ has infinitely many sign changes when $n$ ranges over all positive integers and $b, b_1$ are distinct integers larger than 1.
	
	Moreover, Harminc and Sot\'{a}k \cite{HS} studied palindromes in arithmetic progressions and proved that for $a, b \geq 2, d \in \mathbb{N}$, there are infinitely many $b$-adic palindromes that are congruent to $a \mod{d}$ if and only if $b \nmid a$ or $b \nmid d$. 
	Col \cite{Col} extended Harminc and Sot\'{a}k's result and obtained some distributional theorems concerning $A_b (m, q, r)$ and $A_b (m)/q$ for all $b \geq 2$ satisfying $\gcd (q, b(b^2 - 1)) = 1$.
	In 2015, P\'{a}lv\"{o}lgyi (aka ``Domotorp'') asked on MathOverflow \cite{Domo} whether or not there exists an arbitrarily long arithmetic progression whose members are palindromes. 
	Tao \cite{Tao} gave a negative answer to P\'{a}lv\"{o}lgyi's question, and from his comments, it seems that arithmetic progressions of palindromes should have length no more than $10^8$. 
	Pongsriiam \cite{Pong} then proved that the length of an arithmetic progression of palindromes (in base 10) is at most $10$.
	
	In this article, we consider palindromes in arithmetic progressions and obtain exact formulas for $A_b (m,q,r)$ where $b \equiv 0, 1 \pmod{q}$. This improves Pongsriiam and Subwattanachai's result, which focuses only on the case $q \leq 2$.
	It also supplements Col's theorem, which is restricted to the case $\gcd(q, b(b^2 - 1)) = 1$.
	
	For more information on the palindromes, we refer the reader to Banks \cite{Bank}, Cilleruelo, Luca, and Baxter \cite{Cil}, and Rajasekaran, Shallit, and Smith \cite{RSS} for additive properties of palindromes, Banks, Hart, and Sakata \cite{Bank2} and Banks and Shparlinski \cite{Bank3} for some multiplicative properties of palindromes, Ba\u{s}i\'{c} \cite{Basic, Basic2}, Di Scala and Sombra \cite{DS}, Goins \cite{Goins}, Luca and Togb\'{e} \cite{LTo} for the study of palindromes in different bases, Cilleruelo, Luca, and Tesoro \cite{CLT} for palindromes in linear recurrence sequences, and Korec \cite{Korec} for nonpalindromic numbers having palindromic squares.
	
	\section{Preliminaries and lemmas}
	
	In this section, we provide some definitions and lemmas that are needed in the proof of the main theorems.
	Recall that for a real number $ x $, 
	$ \lfloor x \rfloor $ is the largest integer less than or equal to $ x $ and  $ \lceil x \rceil$ is the smallest integer greater than or equal to $ x $. In addition, we write $a \bmod{m}$ to denote the least nonnegative residue of $a$ modulo $m$. 
	We also use the \textit{Iverson notation}: if $ P $ is a mathematical statement, then 
	$$
	[P]
	=
	\begin{cases}
		1,	&amp;\text{if $ P $ holds;}\\
		0,	&amp;\text{otherwise.}
	\end{cases} 
	$$
	Throughout this article, the empty sum is defined to be zero. It is also convenient to define  $ C_b(m) $ for each $ m\in\mathbb{N} $ as follows:
	\begin{definition}
		Let $b \geq 2$ and $m = \left( a_k a_{k - 1} \cdots a_1 a_0 \right)_b$ be positive integers. 
		We define $C_b (m) = \left( c_k c_{k - 1} \cdots c_1 c_0 \right)_b$ to be the $b$-adic palindrome satisfying $c_i = a_i$ for $k - \lfloor k/2 \rfloor \leq i \leq k$.
		In other words, $C_b (m)$ is the $b$-adic palindrome having $k + 1$ digits whose first half digits are the same as those of $m$ in its $b$-adic expansion, that is, $C_b (m) = ( a_k a_{k - 1} \cdots a_{k - \left\lfloor k/2 \right\rfloor} \cdots a_{k-1} a_k )_b$.
	\end{definition}
	
	For example, if $m = \left( 134240 \right)_5 = \left( 12702 \right)_8$, then $C_5 (m) = (134431)_5$ and $C_8 (m) = (12721)_8$.
	In the next lemma and throughout this article, we let $s_b (n)$ be the sum of digits of $n$ in base $b$, that is, if $n = (a_k a_{k - 1} \cdots a_0)_b$, then $s_b (n) = \sum_{0 \leq i \leq k} a_i$.
	
	\begin{lemma}\label{mainlemma}
		Let $b, n, q, r$ be integers, $b \geq 2$, $n,q \geq 1$,  and $n = \left( a_k a_{k - 1} \cdots a_1 a_0 \right)_b$.
		Then the following statements hold.
		\begin{itemize}
			\item[\emph{(i)}] Assume that $b \equiv \modd{0}{q}$. Then $n \equiv  \modd{r}{q}$ if and only if $a_0 \equiv \modd{r}{q}$.
			\item[\emph{(ii)}] Assume that $b \equiv \modd{1}{q}$. Then $n \equiv  \modd{r}{q}$ if and only if $s_b (n) \equiv \modd{r}{q}$.
		\end{itemize}
	\end{lemma}
	
	\begin{proof}
		For (i), we have $n = \sum_{0 \leq j \leq k} a_j b^{j} \equiv \modd{a_0}{q}$, which implies that $n \equiv \modd{r}{q}$ if and only if $a_0 \equiv \modd{r}{q}$. For (ii), we have
		\begin{equation*}
			n = \sum_{0 \leq j \leq k} a_j b^j \equiv \modd{\sum_{0 \leq j \leq k} a_j}{q},
		\end{equation*}
		which implies the desired result.
	\end{proof}
	
	It is convenient to have a lemma that gives the number of positive integers $n \leq x$ lying in a residue class $a \bmod{q}$.
	It is also useful to define the following function.
	
	\begin{definition}
		Let $b, q, k \in \mathbb{N}$ and $r,x,y \in \mathbb{Z}$. We define $N_b (k,q,r,x,y)$ to be the number of integer solutions to the congruence
		\begin{equation*}
			x_1 + x_2 + \cdots + x_k \equiv \modd{r}{q},	
		\end{equation*}
		where $x \leq x_1 &lt; y$ and $0 \leq x_i &lt; b$ for each $i = 2,3,\ldots, k$. In addition, we let 
		\begin{equation*}
			N_b (k,q,r) = N_b (k,q,r,0,b).
		\end{equation*}
	\end{definition}
	
	\begin{lemma}\label{countinglemma 2}
		Let $a, q \in \mathbb{N}$ and $r\in \mathbb{Z}$. Then
		\begin{equation*}
			\sum_{\substack{0 \leq n &lt; a \\ \text{$n \equiv \modd{r}{q}$}}} 1 = \lfloor a/q \rfloor + [r \bmod{q} &lt; a \bmod{q}].
		\end{equation*}
	\end{lemma}
	
	\begin{proof}
		We can assume that $0 \leq r &lt; q$.
		Let $s = a \bmod{q}$ and write $a = \ell q + s$ for some $\ell \in \mathbb{N}_0$.
		If $r&lt;s$, then there are $\ell + 1 = \left\lfloor a/q \right\rfloor + 1$ choices for $n \in \{r, q + r, 2q + r, \ldots,  \ell q + r\}$. Similarly, If $r \geq s$, there are $\ell = \left\lfloor a/q \right\rfloor$ choices for $n \in \{r, q + r, 2q + r, \ldots, (\ell - 1)q + r\}$. In any case, there are $\left\lfloor a/q \right\rfloor + [r&lt;s]$ possible values for $n$. This completes the proof.
	\end{proof}
	
	The next lemma is an important tool in obtaining the main results. Recall that, throughout this article, we write $a \bmod{m}$ to denote the least nonnegative residue of $a$ modulo $m$.
	
	\begin{lemma}\label{countinglemma}
		Let $a, b, k, q, r \in \mathbb{Z}$ and $a, b, k, q \geq 1$. Assume that $b \equiv \modd{1}{q}$. Then the following statements hold.
		\begin{itemize}
			\item[\emph{(i)}] $N_b (k,q,r) = \frac{b^k - 1}{q} + [r \equiv \modd{0}{q}]$.
			\item[\emph{(ii)}] $N_b (k,q,r,1,b) = \frac{b^k - b^{k - 1}}{q}$.
			\item[\emph{(iii)}] $N_b (k,q,r,0,a) = \frac{a (b^{k - 1} - 1)}{q}  + \lfloor a/q \rfloor + [r \bmod{q} &lt; a \bmod{q}]$.
			\item[\emph{(iv)}] $N_b (k,q,r,1,a) = \frac{(a - 1) ( b^{k - 1} - 1)}{q} + \lfloor a/q \rfloor + [r \bmod{q} &lt; a \bmod{q}] - [r \equiv \modd{0}{q}]$.
		\end{itemize}
	\end{lemma}
	
	\begin{proof}
		We can assume that $0 \leq r &lt; q$ and let $s = a \bmod{q}$.
		We prove (i) by induction on $k$.
		Since $b \equiv \modd{1}{q}$, we obtain by Lemma \ref{countinglemma 2} that
		\begin{equation*}
			N_b (1,q,r) = \sum_{\substack{0 \leq x &lt; b \\ \text{$x \equiv \modd{r}{q}$}}} 1  = \lfloor b/q \rfloor + [r &lt; 1] = \frac{b - 1}{q} + [r = 0].
		\end{equation*}
		Next, we let $k \geq 1$ be integers and assume that $N_b (k,q,r) =(b^k - 1)/q + [r = 0]$.
		Since
		\begin{equation*}
			x_1 + \cdots + x_k + x_{k + 1} \equiv \modd{r}{q} \ \ \text{if and only if}\ \ x_1 + \cdots + x_k \equiv \modd{r - x_{k + 1}}{q},
		\end{equation*} 
		we see that
		\begin{align*}
			N_b (k + 1, q, r) &amp;= \sum_{0 \leq x_{k + 1} &lt; b} N_b \left( k, q, (r - x_{k + 1}) \bmod{q} \right) \\
			&amp;= \sum_{0 \leq x_{k + 1} &lt; b} \left( \frac{b^{k} - 1}{q} + [r - x_{k+1} \equiv \modd{0}{q}] \right) \\
			&amp;= \frac{b \left(b^k - 1\right)}{q} + \sum_{0\leq x_{k + 1} &lt; b} [x_{k + 1} \equiv \modd{r}{q}] \\
			&amp;= \frac{b \left(b^k - 1\right)}{q} + N_b (1, q, r) \\
			&amp;= \frac{b \left(b^k - 1\right)}{q} + \frac{b - 1}{q} + [r = 0] \\
			&amp;= \frac{b^{k + 1} - 1}{q} + [r = 0].
		\end{align*}
		This proves (i).
		For (ii), if $k = 1$, then we obtain by Lemma \ref{countinglemma 2} that
		\begin{equation*}
			N_b (k,q,r,1,b) = \sum_{\substack{0 \leq x &lt; b \\ \text{$x \equiv \modd{r}{q}$}}} 1  - [r = 0] = \lfloor b/q \rfloor + [r &lt; 1] - [r = 0] = \frac{b - 1}{q}.
		\end{equation*}
		If $k \geq 2$, then we obtain by (i) that
		\begin{equation*}
			N_b (k,q,r,1,b) = N_b (k, q, r) - N_b (k - 1, q, r) = \frac{b^k - b^{k - 1}}{q}.
		\end{equation*}
		For (iii), we obtain by Lemma \ref{countinglemma 2} that 
		\begin{equation*}
			N_b (1,q,r,0,a) = \sum_{\substack{0 \leq x &lt; a \\ \text{$x\equiv \modd{r}{q}$} }} 1 = \lfloor a/q \rfloor + [r &lt; s].
		\end{equation*}
		Now, suppose $k \geq 2$. We first fix $0 \leq x_1 &lt; a$ and then count the remaining $x_i$. From (i) and Lemma \ref{countinglemma 2}, we obtain that
		\begin{align*}
			N_b (k,q,r,0,a) &amp;= \sum_{0 \leq x_1 &lt; a} N_b (k - 1, q, (r - x_1) \bmod{q}) \\
			&amp;= \sum_{0 \leq x_1 &lt; a} \left( \frac{b^{k - 1} - 1}{q}  + [x_1 \equiv \modd{r}{q}]\right) \\
			&amp;= \frac{a (b^{k - 1} - 1)}{q}  +  \lfloor a/q \rfloor + [r &lt; s],
		\end{align*}
		as desired. For (iv), if $k = 1$, then 
		\begin{equation*}
			N_b (1,q,r,1,a) = N_b (1,q,r,0,a) - [r \equiv \modd{0}{q}] = \lfloor a/q \rfloor + [r &lt; s] - [r = 0].
		\end{equation*}
		If $k \geq 2$, then we obtain by (i) and (iii) that
		\begin{equation*}
			N_b (k,q,r,1,a) = N_b (k,q,r,0,a) - N_b (k - 1,q,r) = \frac{(a - 1) ( b^{k - 1} - 1)}{q} + \lfloor a/q \rfloor + [r &lt; s] - [r = 0].
		\end{equation*}
		This completes the proof.
	\end{proof}
	
	We will deal with some calculations involving the floor function. So it is useful to recall the following results, which will be applied throughout this article sometimes without reference.
	
	\begin{lemma}\label{floorlemma}
		For $k\in\mathbb{Z}$ and $x\in\mathbb{R}$, the following statements hold.
		\begin{itemize}
			\item[\emph{(i)}] $\lfloor k+x\rfloor = k + \lfloor x\rfloor$,
			\item[\emph{(ii)}] $\{k+x\}=\{x\}$,
			\item[\emph{(iii)}] $\lfloor x\rfloor + \lfloor -x \rfloor=
			\begin{cases}
				-1, &amp;\text{if $x\not\in\mathbb{Z}$;}\\
				0, &amp;\text{if $x\in\mathbb{Z}$,}
			\end{cases}$
			\item[\emph{(iv)}] $0 \leq \{ x \} &lt; 1$ and $\{ x \} = 0$ if and only if $x \in \mathbb{Z}$.
			\item[\emph{(v)}] $\lfloor x+y\rfloor =
			\begin{cases}
				\lfloor x\rfloor +\lfloor y\rfloor, &amp;\text{if $\{x\}+\{y\}&lt;1$;}\\
				\lfloor x\rfloor +\lfloor y\rfloor+1, &amp;\text{if $\{x\}+\{y\}\geq 1$,}
			\end{cases}$
			\item[\emph{(vi)}] $\lfloor \lfloor x\rfloor / k\rfloor = \lfloor x/k \rfloor$ for $k\geq 1$.
		\end{itemize}
	\end{lemma}
	
	\begin{proof}
		These are well-known and can be proved easily. For more details, see in the books by Graham, Knuth, and Patashnik \cite[Chapter 3]{Concrete} and Pongsriiam \cite[Chapter 3]{Pong0}.
	\end{proof}
	
	
	
	
	
	\section{Main results}
	
	In this section, we determine the formula for $A_b (m, q, r)$ where $b \equiv \modd{0 \text{ or } 1}{q}$.
	Since the case $b \equiv \modd{0}{q}$ is easier than the other case, we begin with $b \equiv \modd{0}{q}$ as follows. 
	
	\subsection{The case $b\equiv \modd{0}{q}$}
	
	\begin{theorem}\label{thm:bcon0(q)}
		Let $ b \geq 2 $ and $ m,q \geq 1 $ be integers, and $b\equiv \modd{0}{q}$. Let
		\begin{equation*}
			m = (a_k a_{k-1}\cdots a_1 a_0)_b \ \ \text{and}\ \ \alpha = \alpha_m = \frac{b^{\left\lceil k/2 \right\rceil} + b^ {\left\lfloor k/2 \right\rfloor} - 2}{b - 1}.
		\end{equation*}
		Then $A_{b}(m,q,0)$ is equal to
		\begin{equation}\label{eq:eqinthm1(2)}
			\left(\frac{b}{q}-1\right) \alpha + \left\lfloor\frac{a_k-1}{q}\right\rfloor b^{\left\lfloor k/2 \right\rfloor}+[a_k \equiv \modd{0}{q}]\left(\sum_{1\leq i\leq \lfloor k/2 \rfloor}a_{k-i}b^{\left\lfloor k/2 \right\rfloor-i} + [m \geq C_b (m)] \right),
		\end{equation}
		and if $r \bmod{q} &gt; 0$, then $A_{b}(m,q,r)$ is equal to
		\begin{equation}\label{eq:eqinthm1(1)}
			\frac{b\alpha}{q} + \left\lceil\frac{a_k- (r \bmod{q})}{q}\right\rceil b^{\left\lfloor k/2 \right\rfloor}+[a_{k} \equiv \modd{r}{q}]\left(\sum_{1\leq i\leq \lfloor k/2 \rfloor}a_{k-i}b^{\left\lfloor k/2 \right\rfloor-i} +[m \geq C_b (m)] \right).
		\end{equation}
	\end{theorem}
	
	\begin{proof}
		Throughout this proof, we apply Lemma \ref{mainlemma}(i) repeatedly without reference.
		We can assume that $0 \leq r &lt; q$ and let
		\begin{equation*}
			m^* = \sum_{0 \leq i \leq \lfloor k/2 \rfloor} a_{k - i}b^{k - i} = ( a_k a_{k-1}  \cdots a_{k - \left\lfloor k/2 \right\rfloor} 0 0 \cdots 0 )_b.
		\end{equation*}
		Since $b\equiv 0\pmod{q}$, there exists an integer $\ell \geq 1$ such that $b=\ell q$.
		We have
		\begin{equation}\label{eq:eqinproofthm1(1)}
			A_{b} (m,q,r) = \sum_{\substack{n\in P_b(m) \\\text{$ n\equiv \modd{r}{q}$}} }1 = \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$n&lt; b^k$}} }1+\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^k \leq n &lt; a_kb^k$}} }1 + \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$ a_kb^k\leq n &lt; m^*$}} }1 + \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$ m^* \leq n \leq m$}} }1.
		\end{equation}
		In the first and second rightmost sum in \eqref{eq:eqinproofthm1(1)}, we see that if $a_k b^k \leq n \leq m$, then the leftmost digit of $n$ in its $b$-adic expansion is $a_k = a_0$. Therefore \eqref{eq:eqinproofthm1(1)} implies that
		\begin{equation}\label{eq4.5thm1}
			A_{b}(m,q,r) = \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$n&lt; b^k$}} }1+\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^k \leq n &lt; a_kb^k$}} }1 + [a_k \equiv \modd{r}{q}]\left( \sum_{\substack{n\in P_b \\\text{$ a_kb^k\leq n &lt; m^*$}} }1 + \sum_{\substack{n\in P_b \\\text{$ m^* \leq n \leq m$}} }1 \right).
		\end{equation}
		We divide the calculation into 4 parts according to the sums appearing on the right-hand side of \eqref{eq4.5thm1}.
		
		{\bf Part 1} We calculate the first sum on the right-hand side of \eqref{eq4.5thm1} and divide the consideration into two cases depending on $r$.
		
		{\bf Case 1.1} $r = 0$. We first show that
		\begin{equation}\label{eq4thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$b^t \leq n&lt; b^{t + 1}$}} } 1 = \left(\frac{b}{q}-1\right)b^{\left\lfloor t/2 \right\rfloor} \ \ \text{for all integers $t \geq 0$}.
		\end{equation}
		Let $t \geq 0$ be an integer.
		The left-hand side of \eqref{eq4thm1} counts the number of $ b$-adic palindromes that have $t + 1$ digits in their $b$-adic expansion and are congruent to $0$ modulo $q$. 
		Since $b=\ell q$, such the numbers are of the form $ n=(c_t c_{t-1}\cdots c_1c_0)_b $ where $c_t \in \{q, 2q, \ldots, (\ell-1)q \}$, $c_i \in \{ 0, 1, 2, \ldots , b-1 \}$, and $c_i = c_{t-i} $ for all $ i\in \{0,1,2,\ldots,\left\lfloor t/2\right\rfloor\} $. 
		So there are $ \ell-1=\left( b/q-1\right)$ choices for $ c_t $ and, after $ c_t $ is chosen, there is only one choice for $ c_0=c_t $. There are $ b $ possible values for $ c_{t-1}\in \{0,1,\ldots,b-1\} $ and there is one possible value for $ c_1=c_{t-1} $.
		In general, there are $ b $ choices for $ c_{t-i} $ for $ 1\leq i\leq\left\lfloor t/2\right\rfloor $ and exactly one choice for the corresponding $ c_i $. 
		Therefore
		\begin{equation*}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$b^t\leq n&lt; b^{t+1}$}} }1 
			=\left( \frac{b}{q}-1\right) \cdot\underbrace{ b \cdot b\cdots b}_{
				\lfloor t/2 \rfloor \text{ terms}}
			= \left( \frac{b}{q}-1\right) b^{\left\lfloor t/2 \right\rfloor}.
		\end{equation*}
		This proves \eqref{eq4thm1}. Then \eqref{eq4thm1} implies that
		\begin{equation}\label{eq5thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$1\leq n&lt; b^k$}} } 1 = \sum_{i = 0}^{k- 1} \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$b^i \leq n&lt; b^{i + 1}$}} } 1  = \sum_{i=0}^{k-1}\left( \frac{b}{q}-1\right)b^{\left\lfloor i/2 \right\rfloor} = \left(\frac{b}{q}-1\right)\sum_{1\leq i \leq k}b^{\left\lfloor (i - 1)/2 \right\rfloor}.
		\end{equation}
		If $k$ is even, then \eqref{eq5thm1} is 
		\begin{equation*}
			\left( \frac{b}{q} - 1 \right)\left( 2 + 2b + \cdots 2b^{(k - 2)/2} \right) = 2\left( \frac{b}{q} - 1 \right)\frac{b^{k/2} - 1}{b - 1} = \left( \frac{b}{q} - 1 \right) \frac{b^{\left\lceil k/2 \right\rceil} + b^ {\left\lfloor k/2 \right\rfloor} - 2}{b - 1}.
		\end{equation*}
		Similarly, if $k$ is odd, then \eqref{eq5thm1} becomes
		\begin{align*}
			\left( \frac{b}{q} - 1 \right)\left( 2 + 2b + \cdots + 2b^{(k - 3)/2} + b^{(k - 1)/2} \right) &amp;= \left( \frac{b}{q} - 1 \right) \left( \frac{2\left( b^{(k - 1)/2} - 1 \right) + (b - 1)b^{(k - 1)/2}}{b - 1} \right) \\
			&amp;= \left( \frac{b}{q} - 1 \right) \frac{b^{\left\lceil k/2 \right\rceil} + b^ {\left\lfloor k/2 \right\rfloor} - 2}{b - 1}.
		\end{align*}
		From the above observation and \eqref{eq5thm1}, we obtain
		\begin{equation}\label{eq5.5thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$1\leq n&lt; b^k$}} } 1 = \left( \frac{b}{q} - 1 \right) \frac{b^{\left\lceil k/2 \right\rceil} + b^ {\left\lfloor k/2 \right\rfloor} - 2}{b - 1} = \left( \frac{b}{q} - 1 \right) \alpha.
		\end{equation}
		
		{\bf Case 1.2} $r \neq 0$. Similar to Case 1, we first show that 
		\begin{equation}\label{eq6thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^t \leq n&lt; b^{t + 1}$}} } 1 = \frac{b^{1 + \left\lfloor t/2 \right\rfloor}}{q} \ \ \text{for all integers $t \geq 0$}.
		\end{equation}
		Let $t \geq 0$ be an integer and $n = (c_t c_{t - 1} \cdots c_1 c_0)_b$ a $b$-adic palindrome that is counted in the left-hand side of \eqref{eq6thm1}. Then $c_t \in \{ r, q+r, 2q+r, \ldots, (\ell - 1)q + r \}$, $c_i \in \{0, 1, 2, \ldots, b-1\}$, and $c_i = c_{t - i}$ for all $i \in \{ 0, 1, 2, \ldots , \left\lfloor t/2 \right\rfloor  \}$. 
		So there are $\ell = b/q$ possible values for $c_t$ and there is only one possible value for $c_0$.  For each $1 \leq i \leq \left\lfloor t/2 \right\rfloor$, there are $b$ choices for $c_{t - i}$ and exactly one choice for the corresponding $c_i$. This leads to
		\begin{equation*}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^t\leq n&lt; b^{t+1}$}} }1 
			= \frac{b}{q} \cdot\underbrace{ b \cdot b\cdots b}_{
				\lfloor t/2 \rfloor \text{ terms}}
			= \frac{b^{1 + \left\lfloor t/2 \right\rfloor}}{q}.
		\end{equation*}
		Therefore
		\begin{equation}\label{eq7thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$1\leq n&lt; b^k$}} } 1 = \sum_{i = 0}^{k- 1} \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^i \leq n&lt; b^{i + 1}$}} } 1  = \sum_{i=0}^{k-1} \frac{b^{1 + \left\lfloor i/2 \right\rfloor}}{q} = \frac{b}{q}\sum_{1\leq i \leq k}b^{\left\lfloor (i - 1)/2 \right\rfloor}.
		\end{equation}
		The right-hand side of \eqref{eq7thm1} can be evaluated in a similar way as \eqref{eq5thm1}, which leads to
		\begin{equation}\label{eq7.5thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$1\leq n&lt; b^k$}} } 1 = \frac{b\alpha}{q}.
		\end{equation}
		
		{\bf Part 2} We calculate the second sum on the right-hand side of \eqref{eq4.5thm1}, and divide the calculation into two cases.
		
		{\bf Case 2.1} $r = 0$. We show that
		\begin{equation}\label{eq:eqinproofthm1step6(1)}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$b^k\leq n &lt; a_k b^k$.}}}1=\left\lfloor\frac{a_k -1}{q}\right\rfloor b^{\left\lfloor k/2 \right\rfloor}.
		\end{equation}
		The left-hand side of \eqref{eq:eqinproofthm1step6(1)} counts the integers of the form $n = (c_k c_{k-1} \cdots c_1 c_0)_b$ where 
		\begin{equation*}
			1 \leq c_k &lt; a_k,\ \ c_k \equiv \modd{0}{q},\ \ c_i \in \{ 0, 1, 2, \ldots, b-1 \},\ \ \text{and}\ \ c_i = c_{k-i},
		\end{equation*}
		for all $i \in [0, \lfloor k/2 \rfloor] \cap \mathbb{Z}$.
		We write $a_k = xq + y$ where $x,y \in \mathbb{Z}$ and $0 \leq y &lt; q$. Since $1 \leq a_k &lt; b$ and $b = \ell q$, we have $0 \leq x \leq \ell - 1$.
		If $y = 0$, then  $x \geq 1$ and $c_k \in \{ q, 2q, \ldots, (x - 1)q  \}$, and so there are 
		\begin{equation*}
			x - 1 = \left\lfloor \frac{xq - 1}{q} \right\rfloor = \left\lfloor \frac{a_k - 1}{q} \right\rfloor \ \ \text{possible values for $c_k$}.
		\end{equation*}
		If $1 \leq y &lt; q$, then $c_k \in \{ q, 2q, \ldots, xq  \}$, so there are $x = \left\lfloor (xq + y - 1)/q \right\rfloor = \left\lfloor (a_k - 1)/q \right\rfloor$ possible values for $c_k$.
		In any case, there are $\left\lfloor (a_k - 1)/q \right\rfloor$ possible values for $c_k$, and after $c_k$ is chosen, there is only one possible value for $c_0 = c_k$. There are $ b $ choices for $ c_{k-i} $ for $ 1\leq i\leq\left\lfloor k/2 \right\rfloor $ and exactly one choice for the corresponding $c_i$. Therefore 
		\begin{equation*}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{0}{q}$}\\\text{$b^k\leq n&lt; a_k b^{k+1}$}} }1 
			=\left\lfloor\frac{a_k-1}{q}\right\rfloor\cdot\underbrace{ b \cdot b\cdots b}_{
				\lfloor k/2 \rfloor \text{ terms}}
			= \left\lfloor\frac{a_k -1}{q}\right\rfloor b^{\left\lfloor k/2 \right\rfloor}.
		\end{equation*}
		
		{\bf Case 2.2} $r \neq 0$. This case is similar to Case 1. We show that
		\begin{equation}\label{eq9.5thm1}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^k\leq n &lt; a_k b^k$.}}}1=\left\lceil\frac{a_k -r}{q}\right\rceil b^{\left\lfloor k/2 \right\rfloor}.
		\end{equation}
		Let $n = (c_k c_{k-1} \cdots c_1 c_0)_b$ be a $b$-adic palindrome that is counted in the left-hand side of \eqref{eq9.5thm1}. Then $1 \leq c_k &lt; a_k$, $c_k \equiv \modd{r}{q}$, $c_i \in \{0, 1, 2, \ldots, b-1 \}$, and $c_i = c_{k - i}$ for all $i = 0, 1, 2, \ldots, \left\lfloor k/2 \right\rfloor $.
		We write $a_k = xq + y$ where $0 \leq x \leq \ell - 1$ and $0 \leq y &lt; q$.  If $y \leq r$, then $c_k \in \{ r, q + r, 2q + r, \ldots, (x - 1)q + r \}$, so there are $x = \left\lceil (xq + y - r)/q \right\rceil = \left\lceil ( a_k - r)/q \right\rceil$ possible values for $c_k$. If $y &gt; r$, then $c_k \in \{ r, q + r, 2q + r, \ldots, xq + r \}$, so there are $x + 1 = \left\lceil (xq + y - r)/q \right\rceil = \left\lceil (a _k - r)/q \right\rceil$ possible values for $c_k$. In any case, there are $\left\lceil (a_k - r)/q \right\rceil$ possible values for $c_k$, and after $c_k$ is chosen, there is only one possible value for $c_0$. For each $1 \leq i \leq \left\lfloor k/2 \right\rfloor$, there are $b$ choices for $c_{k - i}$ and exactly one choice for the corresponding $c_i$. Therefore
		\begin{equation*}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^k\leq n&lt; a_k b^{k+1}$}} }1 
			=\left\lceil\frac{a_k-r}{q}\right\rceil\cdot\underbrace{ b \cdot b\cdots b}_{
				\lfloor k/2 \rfloor \text{ terms}}
			= \left\lceil\frac{a_k -r}{q}\right\rceil b^{\left\lfloor k/2 \right\rfloor},
		\end{equation*}
		as desired.
		
		{\bf Part 3} We compute the third sum in \eqref{eq4.5thm1}. For each $j \in  \left\{0,1,\ldots,\left\lfloor k/2 \right\rfloor \right\}$, let 
		\begin{equation*}
			m_j = \sum_{0 \leq i \leq j} a_{k-i}b^{k-i} = (a_k a_{k-1}\cdots a_{k-j} 0 0\cdots 0)_b.
		\end{equation*}
		Then
		\begin{equation}\label{eq8thm1}
			\sum_{\substack{n\in P_b \\\text{$ a_kb^k\leq n &lt; m^*$}} } 1  = \sum_{1 \leq j \leq \lfloor k/2 \rfloor} \sum_{\substack{n\in P_b \\ m_{j-1} \leq n &lt; m_j}}1.
		\end{equation}
		We first show that for $ 1 \leq j \leq \left\lfloor k/2 \right\rfloor $,
		\begin{equation} \label{eq:eqinproofthm1step8(1)}
			\sum_{\substack{n\in P_b \\ m_{j-1} \leq n &lt; m_j} }1 = a_{k-j} b^{\left\lfloor k/2 \right\rfloor - j} .
		\end{equation}
		Let $n = (c_k c_{k-1} \ldots c_1c_0)_b$ be an integer that is counted in the left-hand side of \eqref{eq:eqinproofthm1step8(1)}. 
		We see that $ m_{j-1} = (a_k a_{k-1}\cdots a_{k-(j-1)} 0 0\cdots 0)_b $ and $ m_j = (a_k a_{k-1}\cdots a_{k-j} 0 0\cdots 0)_b $. Then there is only one possible value for each $c_k, c_{k-1}, \ldots, c_{k - j + 1}$, namely, $c_k = a_k, c_{k - 1} = a_{k - 1}, \ldots, c_{k - j + 1} = a_{k - j + 1}$. In addition, there is only one choice for each $c_0, c_1, \ldots, c_{j - 1}$ since $c_{k - i} = c_{i}$ for $i = 0,1,\ldots, j - 1$.
		Since $c_{k - j} \in \{ 0,1,2, \ldots a_{k - j} - 1 \}$, there are $a_{k - j}$ choices for $c_{k - j}$.
		The remaining digits $ c_{k-i} $, where $ j+1 \leq i \leq \left\lfloor k/2 \right\rfloor $, can be chosen arbitrarily from $ 0,1,\ldots, b-1 $. So the left-hand side of \eqref{eq:eqinproofthm1step8(1)} is equal to
		\begin{equation*}
			a_{k-j} \cdot \underbrace{ b \cdot b\cdots b}_{
				\lfloor k/2 \rfloor-j \text{ terms}}
			=
			a_{k-j}b^{\left\lfloor k/2 \right\rfloor-j}.
		\end{equation*}
		This proves \eqref{eq:eqinproofthm1step8(1)}. From \eqref{eq8thm1} and \eqref{eq:eqinproofthm1step8(1)}, we obtain
		\begin{equation}\label{eq10thm1}
			\sum_{\substack{n\in P_b \\\text{$ a_kb^k\leq n &lt; m^*$}} } 1  = \sum_{1 \leq j \leq \lfloor k/2 \rfloor} a_{k-j}b^{\left\lfloor k/2 \right\rfloor-j}.
		\end{equation}
		
		{\bf Part 4} We calculate the last sum in \eqref{eq4.5thm1}. 
		Recall that $ m = (a_k a_{k-1}\cdots a_1 a_0)_b $ and $m^* = ( a_k a_{k-1}  \cdots a_{k - \left\lfloor k/2 \right\rfloor} 0 0 \cdots 0 )_b$. The only possible palindrome $ n $ such that 
		$ m^* \leq n \leq m $
		is $ n = C_b(m)$. So the number of such palindromes is 1 if $ m \geq C_b(m) $ and is 0 otherwise. That is
		\begin{equation} \label{eq12thm1}
			\sum_{\substack{n\in P_b \\ m^* \leq n \leq m } }1 
			=
			[m \geq C_b (m)].
		\end{equation}	
		Therefore we obtain the formula \eqref{eq:eqinthm1(2)} from \eqref{eq5.5thm1}, \eqref{eq:eqinproofthm1step6(1)}, \eqref{eq10thm1}, and \eqref{eq12thm1}, and the formula \eqref{eq:eqinthm1(1)} from \eqref{eq7.5thm1}, \eqref{eq9.5thm1}, \eqref{eq10thm1}, and \eqref{eq12thm1}. This completes the proof.
	\end{proof}
	
	Applying Theorem \ref{thm:bcon0(q)} with $q = 1, 2$, we obtain Pongsriiam and Subwattanachai's result \cite[Theorems 2.2 and 2.3]{PS} as a corollary.
	
	\begin{corollary}\label{corollary1}
		Let $b \geq 2$ and $m \geq 1$ be integers and $m = (a_k a_{k - 1} \cdots a_1 a_0)_b$. Then
		\begin{equation*}
			A_b (m,1,0) = A_b (m) = b^{\left\lceil k/2 \right\rceil} + \sum_{0 \leq i \leq \lfloor k/2 \rfloor} a_{k - i} b^{\left\lfloor k/2 \right\rfloor - i} + [m \geq C_b (m)] - 2.
		\end{equation*} 
		In addition, if $\alpha =  (b^{\left\lceil k/2 \right\rceil} + b^ {\left\lfloor k/2 \right\rfloor} - 2)/(b - 1)$, $q = 2$, and $b \equiv \modd{0}{2}$, then $A_b (m,2,0)$ is equal to
		\begin{equation*}
			\left(\frac{b}{2}-1\right) \alpha + \left\lfloor\frac{a_k-1}{2}\right\rfloor b^{\left\lfloor k/2 \right\rfloor}+[a_k \equiv \modd{0}{2}]\left(\sum_{1\leq i\leq \lfloor k/2 \rfloor}a_{k-i}b^{\left\lfloor k/2 \right\rfloor-i} + [m \geq C_b (m)] \right),
		\end{equation*}
		and $A_b (m,2,1)$ is equal to
		\begin{equation*}
			\frac{b \alpha}{2} + \left\lceil\frac{a_k-1}{2}\right\rceil b^{\left\lfloor k/2 \right\rfloor}+[a_{k} \equiv \modd{1}{2}]\left(\sum_{1\leq i\leq \lfloor k/2 \rfloor}a_{k-i}b^{\left\lfloor k/2 \right\rfloor-i} +[m \geq C_b (m)] \right).
		\end{equation*}
		
	\end{corollary}
	
	\subsection{The case $b\equiv \modd{1}{q}$}

	
	\begin{theorem}\label{maintheorem2}
		Let $ b \geq 2 $, $ m,q \geq 1 $, and $0 \leq r&lt; q$ be integers, $b \equiv \modd{1}{q}$, and $m = (a_k a_{k - 1} \cdots a_1 a_0)_b$. For each nonnegative integer $j \leq \left\lfloor k/2 \right\rfloor$, let
		\begin{equation*}
			r_{j} =
			\begin{cases}
				\left( r - 2\sum_{0 \leq i \leq (k/2) - 1} a_{k - i} \right) \bmod{q}, &amp;\text{if $j = k/2$;} \\
				\left( \frac{r}{2} - \sum_{0 \leq i \leq j - 1} a_{k - i} \right) \bmod{q/2}, &amp;\text{if $q$ is even and $j \neq k/2$;}\\
				\left( \left( \frac{q + 1}{2} \right) r - \sum_{0 \leq i \leq j - 1} a_{k - i} \right) \bmod{q} , &amp;\text{if $q$ is odd and $j \neq k/2$,}
			\end{cases}
			\ \  \text{and}
		\end{equation*} 
		\begin{equation*}
			s_{j} =
			\begin{cases}
				a_{k - j} \bmod{q/2}, &amp;\text{if $q$ is even and $j \neq k/2$;}\\
				a_{k - j} \bmod{q}, &amp;\text{otherwise.}
			\end{cases}
		\end{equation*}
		Let 
		\begin{equation*}
			m_{1}^* = \sum_{0 \leq j \leq (k - 1)/2} \left( \frac{2 a_{k - j} b^{((k - 1)/2) - j} - 2s_j}{q} + [r_j &lt; s_j] \right), \quad m_{2}^* = \sum_{0 \leq j \leq (k/2) - 1} \frac{a_{k - j} (b - 1) b^{(k/2) - j - 1}}{q},
		\end{equation*}
		\begin{equation*}
			m_{3}^* = \sum_{0 \leq j \leq (k/2) - 1} \left( \frac{ a_{k - j} (b + 1) b^{(k/2) - j - 1} - 2s_j}{q} + [r_j &lt; s_j] \right),\ \ \text{and}
		\end{equation*}
		\begin{equation*}
			\delta(m) = [m \geq C_b (m)] \left[ r_{\left\lfloor k/2 \right\rfloor} = s_{\left\lfloor k/2 \right\rfloor} \right].
		\end{equation*}
		Then the following statements hold.
		\begin{itemize}
			\item[\emph{(i)}] If $q$ is odd, then
			\begin{equation*}
				A_{b} (m,q,r) = \frac{b^{\left\lfloor (k + 1)/2 \right\rfloor} - 1}{q} + \sum_{0 \leq j \leq \lfloor k/2 \rfloor} \left( \left\lfloor \frac{a_{k - j}b^{\left\lfloor k/2 \right\rfloor - j}}{q} \right\rfloor + \left[r_j &lt; s_j \right] \right) - [r = 0] + \delta(m).
			\end{equation*}
			\item[\emph{(ii)}] If $q$ is even, then $A_b (m,q,r)$ is equal to
			\begin{equation*}
				\begin{cases}
					\frac{(b - 1)b^{(k - 1)/2}}{q}, &amp;\text{if $k$ and $r$ are odd;}\\
					\frac{(b + 1)b^{(k - 1)/2} - 2}{q} + m_{1}^* - [r = 0] + \delta (m), &amp;\text{if $k$ is odd and $r$ is even;}\\
					\left\lfloor \frac{a_{k/2}}{q} \right\rfloor + m_{2}^* + \left[r_{k/2} &lt; s_{k/2} \right] + \delta (m), &amp;\text{if $k$ is even and $r$ is odd;}\\
					\frac{2(b^{k/2} - 1)}{q} + \left\lfloor \frac{a_{k/2}}{q} \right\rfloor  + m_{3}^* - [r = 0] + \left[r_{k/2} &lt; s_{k/2} \right] + \delta (m), &amp;\text{if $k$ and $r$ are even.}
				\end{cases}
			\end{equation*}
		\end{itemize}
	\end{theorem}
	
	\begin{remark}\label{remark1}
		In the proof of this theorem, we also show that $\left[ r_{\left\lfloor k/2 \right\rfloor} = s_{\left\lfloor k/2 \right\rfloor} \right]$ can be replaced by $[s_b (C_b (m)) \equiv \modd{r}{q}]$, that is, 
		\begin{equation*}
			\delta(m) = [m \geq C_b (m)] \left[ s_b \left( C_b (m) \right) \equiv \modd{r}{q} \right].
		\end{equation*}
	\end{remark}
	
	\begin{proof}
		If $q = 1$, then $r = 0$ and the result follows from Corollary \ref{corollary1}.
		So assume that $q \geq 2$.
		If $k = 0$, then $m = a_0$ where $1 \leq a_0 &lt; b$, $m = C_b (m)$, and we obtain by Lemma \ref{countinglemma 2} that
		\begin{align*}
			A_b (m, q, r) 
			&amp;= \sum_{\substack{1 \leq n \leq a_0 \\ \text{$n \equiv \modd{r}{q}$}}} 1 = \sum_{\substack{0 \leq n &lt; a_0 \\ \text{$n \equiv \modd{r}{q}$}}} 1 - [r = 0] + [a_0 \equiv \modd{r}{q}] \\
			&amp;= \lfloor a_0 / q \rfloor + [r \bmod{q} &lt; a_0 \bmod{q}] - [r = 0] + [r \bmod{q} = a_0 \bmod{q}] \\
			&amp;=  \lfloor a_0/q \rfloor + [r_0 &lt; s_0] - [r = 0] + \delta(m).
		\end{align*}
		This proves the case $k = 0$.
		For the clarity of the proof, we will also first consider the case $k = 1$, that is, we have $m = (a_1 a_0)_b$.
		Since $b \equiv \modd{1}{q}$, we obtain by Lemma \ref{countinglemma 2} that
		\begin{align}\label{thm2eq00}
			A_b (m, q, r) &amp;= \sum_{\substack{1 \leq n &lt; b \\ \text{$n \equiv \modd{r}{q}$}}} 1 + \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b \leq n \leq m }} 1  \nonumber\\
			&amp;= \frac{b - 1}{q}  + \sum_{\substack {n \in P_b \\ b \leq n &lt; a_1 b \\ \text{$n \equiv \modd{r}{q}$}}} 1 + \sum_{\substack {n \in P_b \\ a_1 b \leq n \leq m \\ \text{$n \equiv \modd{r}{q}$}}} 1.
		\end{align}
		The only possible $b$-adic palindrome that can be counted in the second sum in \eqref{thm2eq00} is $(a_1 a_1)_b = C_b (m)$, and it is actually counted if and only if $m \geq C_b (m)$ and $C_b (m) \equiv \modd{r}{q}$.
		Therefore \eqref{thm2eq00} implies that
		\begin{equation}\label{thm2eq0}
			A_b (m, q, r) =  \frac{b - 1}{q}  + \sum_{\substack {n \in P_b \\ b \leq n &lt; a_1 b \\ \text{$n \equiv \modd{r}{q}$}}} 1 + \delta_1 (m),
		\end{equation}
		where $\delta_1 (m) = [m \geq C_b (m)][C_b (m) \equiv \modd{r}{q}]$. 
		The palindromes counted in the sum on the right-hand side of \eqref{thm2eq0} is of the form $n = (aa)_b$ where $1 \leq a &lt; a_1$ and
		\begin{equation}\label{thm2part0eq1}
			2a \equiv ab + a = n \equiv \modd{r}{q}.
		\end{equation}
		We divide the consideration into two cases.
		
		{\bf Case 1} $q$ is even.
		If $r$ is odd, then \eqref{thm2part0eq1} is not possible and the sum on the right-hand side of \eqref{thm2eq0} is equal to 0.
		Suppose that $r$ is even. Then \eqref{thm2part0eq1} is equivalent to
		\begin{equation*}
			a \equiv \modd{r/2}{q/2}.
		\end{equation*}
		By Lemma \ref{countinglemma}, the sum on the right-hand side of \eqref{thm2eq0} is equal to
		\begin{align*}
			N_b \left( 1, q/2, r/2, 1, a_1 \right) 
			&amp;= \left\lfloor 2a_1 / q \right \rfloor + [r/2 \bmod{q/2} &lt; a_1 \bmod{q/2} ] - [ r/2 \equiv \modd{0}{q/2} ] \\
			&amp;= \frac{2a_{1} - 2s_0}{q} + [r_0 &lt; s_0] - [r = 0].
		\end{align*}
		Therefore \eqref{thm2eq0} becomes
		\begin{equation*}
			A_b (m, q, r) = 
			\begin{cases}
				\frac{b - 1}{q} + \delta_1 (m), &amp;\text{if $r$ is odd;}\\
				\frac{b - 1}{q} + \frac{2a_1 - 2s_0}{q} + [r_0 &lt; s_0] - [r = 0] + \delta_1 (m), &amp;\text{if $r$ is even.}
			\end{cases}
		\end{equation*}
		Since $C_b (m) = a_1 b + a_1 \equiv \modd{2a_1}{q}$, we see that $C_b (m) \equiv \modd{r}{q}$ if and only if
		\begin{equation*}
			2a_1 \equiv \modd{r}{q}.
		\end{equation*}
		So, if $r$ is odd, then $\delta_1 (m) = 0$. 
		If $r$ is even, then the above congruence is equivalent to $a_1 \equiv \modd{r/2}{q/2}$, that is, $r_0 = s_0$, and so $\delta_1 (m) = \delta(m)$.
		Therefore the result follows.
		
		{\bf Case 2} $q$ is odd. This case is similar to Case 1, so we skip some details.
		We see that \eqref{thm2part0eq1} is equivalent to
		\begin{equation*}
			a \equiv \modd{\left(\frac{q + 1}{2} \right) r}{q}.
		\end{equation*}
		In addition, $C_b (m) \equiv \modd{r}{q}$ if and only if $a_1 \equiv \modd{(q + 1)r/2}{q}$, that is, $r_0 = s_0$.
		Therefore $\delta_1 (m) = \delta (m)$ and we obtain from \eqref{thm2eq0} that $A_b (m,q,r)$ is equal to
		\begin{align*}
			&amp;\frac{b - 1}{q} + N_b \left( 1, q, \left( \frac{q + 1}{2} \right)r, 1, a_1 \right) + \delta_1 (m) \\
			&amp;=\frac{b - 1}{q} +  \lfloor a_1/q  \rfloor + \left[\left( \frac{q + 1}{2} \right)r \bmod{q} &lt; a_1 \bmod{q} \right] - [r = 0] + \delta (m) \\
			&amp;= \frac{b - 1}{q} + \lfloor a_1 / q \rfloor + [r_0 &lt; s_0] - [r = 0] + \delta (m),
		\end{align*}
		which proves the result.
		
		Hence from this point on, we assume that $q, k \geq 2$. We will also apply Lemma \ref{mainlemma}(ii) repeatedly without reference. Let
		\begin{equation}\label{thm2eq1}
			m^* = \sum_{0 \leq i \leq \lfloor k/2 \rfloor} a_{k - i}b^{k - i} = ( a_k a_{k-1}  \cdots a_{k - \left\lfloor k/2 \right\rfloor} 0 0 \cdots 0 )_b.
		\end{equation}
		We write
		\begin{equation}\label{maintheorem2eq1}
			A_{b} (m,q,r) = \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$n&lt; b^k$}} }1+\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^k \leq n &lt; a_kb^k$}} }1 + \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$ a_kb^k\leq n &lt; m^*$}} }1 + \sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$ m^* \leq n \leq m$}} }1,
		\end{equation}
		and divide the calculation into 6 parts.
		
		{\bf Part 1} We will show that for integers $t \geq 1$,
		\begin{equation}\label{maintheorem2eq2}
			\sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^t \leq n &lt; b^{t + 1}}} 1 = 
			\begin{cases}
				0, &amp;\text{if $q$ is even, $t$ is odd, and $r$ is odd;} \\
				\frac{2(b - 1)b^{(t - 1)/2}}{q}, &amp;\text{if $q$ is even, $t$ is odd, and $r$ is even;} \\
				\frac{(b - 1)^2 b^{(t/2) - 1}}{q}, &amp;\text{if $q$ is even, $t$ is even, and $r$ is odd;}\\
				\frac{(b - 1)(b + 1)b^{(t/2) - 1}}{q}, &amp;\text{if $q$ is even, $t$ is even, and $r$ is even;} \\[3pt]
				\frac{(b - 1)b^{\left\lfloor t/2 \right\rfloor}}{q}, &amp;\text{if $q$ is odd.}
			\end{cases}
		\end{equation}
		Let $t \geq 1$ be an integer and $n = (c_t c_{t-1} \cdots c_1 c_0)_b$ a $b$-adic palindrome that is counted in the left-hand side of \eqref{maintheorem2eq2}.
		Then we have $s_b (n) \equiv n \equiv \modd{r}{q}$.
		We divide the consideration into four cases according to the parity of $q$ and $t$.
		
		{\bf Case 1.1} $q$ is even and $t$ is odd. We have 
		\begin{equation}\label{maintheorem2eq3}
			2 \sum_{0 \leq j \leq (t - 1)/2} c_{t - j} = \sum_{0\leq j \leq t} c_j = s_b (n) \equiv \modd{r}{q}.
		\end{equation}
		Since $q$ and the leftmost term in \eqref{maintheorem2eq3} are even, we see that $r$ is even.
		So if $r$ is odd, then the left-hand side of \eqref{maintheorem2eq2} is equal to 0, which proves the first case of \eqref{maintheorem2eq2}.
		Since $r$ is even, the congruence in \eqref{maintheorem2eq3} is equivalent to
		\begin{equation*}
			\sum_{0 \leq j \leq (t - 1)/2} c_{t - j}  \equiv \modd{r/2}{q/2}.
		\end{equation*}
		Since $1 \leq c_t &lt; b$ and $0 \leq c_{t - j} &lt; b$ for all integers $j = 1, 2, \ldots, (t - 1)/2$, we obtain by Lemma \ref{countinglemma} that
		\begin{equation*}
			\sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^t \leq n &lt; b^{t + 1}}} 1 = N_b \left(\frac{t + 1}{2}, q/2, r/2, 1, b \right) = \frac{b^{(t + 1)/2} - b^{(t - 1)/2}}{q/2} = \frac{2(b - 1)b^{(t - 1)/2}}{q},
		\end{equation*}
		which proves the second case of \eqref{maintheorem2eq2}.
		
		{\bf Case 1.2} $q$ and $t$ are odd.
		This case is similar to Case 1.1, so we skip some details.
		We also obtain \eqref{maintheorem2eq3}, and \eqref{maintheorem2eq3} is equivalent to
		\begin{equation*}
			\sum_{0 \leq j \leq (t - 1)/2} c_{t - j} \equiv \modd{\left(\frac{q + 1}{2}\right) r}{q}.
		\end{equation*}
		Therefore the left-hand side of \eqref{maintheorem2eq2} is
		\begin{equation*}
			N_b \left(\frac{t + 1}{2}, q, \left(\frac{q + 1}{2} \right) r, 1, b \right) = \frac{(b - 1)b^{(t - 1)/2}}{q}. 
		\end{equation*}
		
		{\bf Case 1.3} $q$ and $t$ are even. In this case, we first fix the value of $c_{t/2}$ and then count the number of choices for the remaining $c_j$. We have
		\begin{equation}\label{maintheorem2eq4}
			c_{t/2} + 2 \sum_{0 \leq j \leq (t/2) - 1}  c_{t - j} = \sum_{0\leq j \leq t} c_j = s_n (n) \equiv \modd{r}{q}.
		\end{equation}
		Then $c_{t/2} \equiv \modd{r}{2}$ and \eqref{maintheorem2eq4} is equivalent to
		\begin{equation*}
			\sum_{0 \leq j \leq (t/2) - 1} c_{t - j} \equiv \modd{\frac{r - c_{t/2}}{2}}{q/2}.
		\end{equation*}
		Since $q$ is even and $b \equiv \modd{1}{q}$, we see that $b \equiv \modd{1}{2}$. By Lemmas \ref{countinglemma 2} and \ref{countinglemma}, we obtain
		\begin{align*}
			\sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^t \leq n &lt; b^{t + 1}}} 1 &amp;= \sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}} N_b \left( t/2, q/2, \frac{r - c}{2}, 1, b \right) \\
			&amp;= \left( \frac{b^{t/2} - b^{(t/2) - 1}}{q/2} \right) \left( \frac{b - 1}{2} + [r \equiv \modd{0}{2}] \right) \\
			&amp;= 
			\begin{cases}
				\frac{(b - 1)(b + 1)b^{(t/2) - 1}}{q}, &amp;\text{if $r$ is even;} \\
				\frac{(b - 1)^2 b^{(t/2) - 1}}{q}, &amp;\text{if $r$ is odd,}
			\end{cases}
		\end{align*}
		which proves the third and fourth cases of \eqref{maintheorem2eq2}. 
		
		{\bf Case 1.4} $q$ is odd and $t$ is even. Using a similar method as in Case 1.3, we obtain \eqref{maintheorem2eq4}, and \eqref{maintheorem2eq4} is equivalent to 
		\begin{equation*}
			\sum_{0 \leq j \leq (t/2) - 1} c_{t - j} \equiv \modd{\left(r - c_{t/2}\right) \left( \frac{q + 1}{2} \right)}{q}.
		\end{equation*}
		Therefore the left-hand side of \eqref{maintheorem2eq2} is
		\begin{equation*}
			\sum_{0 \leq c &lt; b} N_b \left( t/2, q, \left(r - c \right) \left( \frac{q + 1}{2} \right), 1, b \right) 
			= \frac{(b - 1)b^{t/2}}{q}.
		\end{equation*}
		Combining this and the result in Case 1.2, we obtain the last case of \eqref{maintheorem2eq2}.
		
		{\bf Part 2} We let $S_1$ be the first sum on the right-hand side of \eqref{maintheorem2eq1}, and apply \eqref{maintheorem2eq2} to calculate $S_1$.
		It is straightforward to see that
		\begin{equation*}
			\sum_{\substack{1 \leq t \leq k - 1 \\ \text{$t \equiv \modd{0}{2}$}}} b^{(t / 2) - 1} = \frac{b^{\left\lfloor (k - 1)/2 \right\rfloor} - 1}{b - 1} \quad \text{and} \quad
			\sum_{\substack{1 \leq t \leq k - 1 \\ \text{$t \equiv \modd{1}{2}$}}} b^{(t - 1)/2} = \frac{b^{\left\lfloor k/2 \right\rfloor} - 1}{b - 1}.
		\end{equation*}
		In addition, we have $1,2,\ldots, b-1$ are $b$-adic palindromes, $b \equiv \modd{1}{q}$, and $S_1$ is equal to
		\begin{align*}
			&amp; \sum_{0 \leq t \leq k - 1}  \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^{t} \leq n &lt; b^{t + 1}}} 1 \\
			&amp;=  \sum_{\substack{1 \leq n &lt; b \\ \text{$n \equiv \modd{r}{q}$}}} 1  + \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{0}{2}$}}}  \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^{t} \leq n &lt; b^{t + 1}}} 1  + \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{1}{2}$}}}  \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^{t} \leq n &lt; b^{t + 1}}} 1 \\
			&amp;= \lfloor b/q \rfloor + \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{0}{2}$}}}  \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^{t} \leq n &lt; b^{t + 1}}} 1  + \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{1}{2}$}}}  \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ b^{t} \leq n &lt; b^{t + 1}}} 1,
		\end{align*}
		where the first sum is obtained by Lemma \ref{countinglemma 2}.
		If $q$ is even and $r$ is odd, then \eqref{maintheorem2eq2} implies
		\begin{align}
			S_1
			&amp;= \lfloor b/q \rfloor + \frac{(b - 1)^2}{q} \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{0}{2}$}}} b^{(t/2) - 1} \nonumber\\
			&amp;= \frac{b - 1}{q} + \left( \frac{b - 1}{q} \right) \left( b^{\left\lfloor (k - 1)/2 \right\rfloor} - 1 \right) =  \frac{(b - 1)b^{\left\lfloor (k - 1)/2 \right\rfloor}}{q}. \label{thm2part2eq1}
		\end{align}
		Similarly, if $q$ and $r$ are even, then
		\begin{align}
			S_1
			&amp;= \frac{b - 1}{q} + \frac{(b - 1)(b + 1)}{q}  \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{0}{2}$}}} b^{(t/2) - 1}  + \frac{2(b - 1)}{q} \sum_{\substack{1 \leq t \leq k - 1 \\ \text{$t \equiv \modd{1}{2}$}}} b^{(t - 1)/2} \nonumber\\
			&amp;= \frac{b - 1}{q} + \left( \frac{b + 1}{q} \right) \left( b^{\left\lfloor (k - 1)/2 \right\rfloor} - 1 \right) + \frac{2 \left( b^{\left\lfloor k/2 \right\rfloor} - 1 \right)}{q} \nonumber\\
			&amp;= \frac{(b + 1) b^{\left\lfloor (k - 1)/2 \right\rfloor} + 2 b^{\left\lfloor k/2 \right\rfloor} - 4}{q}. \label{thm2part2eq2}
		\end{align}
		If $q$ is odd, then
		\begin{align}
			S_1
			&amp;= \frac{b - 1}{q} + \frac{(b - 1)b}{q} \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{0}{2}$}}} b^{(t/2) - 1} + \frac{(b - 1)}{q} \sum_{\substack{1 \leq t \leq k-1 \\ \text{$t \equiv \modd{1}{2}$}}} b^{(t - 1)/2} \nonumber \\
			&amp;= \frac{b - 1}{q} + \frac{b^{\left\lfloor (k + 1)/2 \right\rfloor} - b}{q} + \frac{b^{\left\lfloor k/2 \right\rfloor} - 1}{q} \nonumber\\
			&amp;= \frac{b^{\left\lfloor (k + 1)/2 \right\rfloor} + b^{\left\lfloor k/2 \right\rfloor} - 2}{q}. \label{thm2part2eq3}
		\end{align}
		From \eqref{thm2part2eq1}, \eqref{thm2part2eq2}, and \eqref{thm2part2eq3}, we obtain
		\begin{equation}\label{maintheorem2eq5}
			\sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ 1 \leq n &lt; b^k}} 1 =
			\begin{cases}
				\frac{(b - 1)b^{\left\lfloor (k - 1)/2 \right\rfloor}}{q}, &amp;\text{if $q$ is even and $r$ is odd;} \\[3pt]
				\frac{(b + 1) b^{\left\lfloor (k - 1)/2 \right\rfloor} + 2 b^{\left\lfloor k/2 \right\rfloor} - 4}{q}, &amp;\text{if $q$ and $r$ are even;} \\[3pt]
				\frac{b^{\left\lfloor (k + 1)/2 \right\rfloor} + b^{\left\lfloor k/2 \right\rfloor} - 2}{q}, &amp;\text{if $q$ is odd.}
			\end{cases}
		\end{equation}
		
		{\bf Part 3} We show that  the second sum on the right-hand side of \eqref{maintheorem2eq1} is equal to
		\begin{equation}\label{maintheorem2eq6} 
			\begin{cases}
				0, &amp;\text{if $q$ is even, $k$ is odd, and $r$ is odd;} \\
				\frac{2 (a_k - 1) b^{ (k - 1)/2} - 2s_0 + 2}{q} +   \left[ r_0 &lt; s_0 \right] - [r = 0], &amp;\text{if $q$ is even, $k$ is odd, and $r$ is even;}\\
				\frac{(a_k - 1) (b - 1) b^{(k / 2) - 1} }{q}, &amp;\text{if $q$ is even, $k$ is even, and $r$ is odd;} \\
				\frac{(a_k - 1) (b + 1) b^{(k / 2) - 1} - 2 s_0 + 2 }{q} + \left[ r_0 &lt; s_0 \right] - [ r = 0], &amp;\text{if $q$ is even, $k$ is even, and $r$ is even;} \\
				\left\lfloor \frac{a_{k} b^{\left\lfloor k/2 \right\rfloor}}{q} \right\rfloor - \frac{b^{\left\lfloor k/2 \right\rfloor} - 1}{q} + [r_0 &lt; s_0] - [r = 0],
				&amp;\text{if $q$ is odd.}
			\end{cases}
		\end{equation}
		Let $n = (c_k c_{k - 1} \cdots c_1 c_0)_b$ be a $b$-adic palindrome satisfying $b^k \leq n &lt; a_k b^k$ and $n \equiv \modd{r}{q}$. We divide the calculation into four cases.
		
		{\bf Case 3.1} $q$ is even and $k$ is odd.  We have
		\begin{equation}\label{maintheorem2eq7}
			2 \sum_{0 \leq j \leq (k - 1)/2} c_{k - j} = \sum_{0 \leq j \leq k} c_j = s_b(n) \equiv \modd{r}{q}.
		\end{equation}
		Since $q$ is even, the second sum on the right-hand side of \eqref{maintheorem2eq1} is zero when $r$ is odd, which proves the first case in \eqref{maintheorem2eq6}.
		Suppose $r$ is even.
		Then \eqref{maintheorem2eq7} is equivalent to 
		\begin{equation*}
			\sum_{0 \leq j \leq (k - 1)/2}  c_{k - j} \equiv \modd{r/2}{q/2}. 
		\end{equation*}
		Recall that $r_0 = r/2 \bmod{q/2}$ and $s_0 = a_k \bmod{q/2}$. In addition, $r_0 = 0$ if and only if $r = 0$ By Lemma \ref{countinglemma} (iv), the second sum on the right-hand side of \eqref{maintheorem2eq1} is equal to
		\begin{align*}
			N_b \left( \frac{k + 1}{2}, q/2, r/2,1,a_k \right) &amp;= \frac{2 (a_k - 1) \left(b^{ (k - 1)/2 } - 1 \right)}{q} + \lfloor 2a_k / q \rfloor + \left[ r_0 &lt; s_0 \right] - [r_0 = 0] \\
			&amp;= \frac{2 (a_k - 1) b^{(k - 1)/2 } - 2s_0 + 2}{q} +   \left[ r_0 &lt; s_0 \right] - [r = 0],
		\end{align*}
		which proves the second case in \eqref{maintheorem2eq6}.
		
		{\bf Case 3.2} $q$ and $k$ are odd. Similar to Case 1.2, we have 
		\begin{equation*}
			\sum_{0 \leq j \leq (k - 1)/2} c_{k - j} \equiv \modd{\left(\frac{q+1}{2}\right)r}{q}.
		\end{equation*}
		Since $b \equiv \modd{1}{q}$, we obtain $a_k b^{(k - 1)/2} \equiv \modd{s_0}{q}$ and so $(a_k b^{(k - 1)/2} - s_0)/q= \lfloor a_k b^{\lfloor k/2 \rfloor }/q \rfloor$.
		Therefore the second sum on the right-hand side of \eqref{maintheorem2eq1} is equal to
		\begin{align*}
			&amp; N_b \left( \frac{k + 1}{2}, q, \left( \frac{q + 1}{2} \right) r, 1, a_k \right) \\
			&amp;= \frac{(a_k - 1)(b^{(k - 1)/2} - 1)}{q} + \lfloor a_k / q \rfloor + \left[\left( \frac{q + 1}{2} \right)r \bmod{q} &lt; a_k \bmod{q} \right] - \left[\left( \frac{q + 1}{2} \right)r \bmod{q} = 0 \right] \\
			&amp;= \frac{a_k b^{(k - 1)/2} - s_0}{q} - \frac{b^{(k - 1)/2} - 1}{q} + [r_0 &lt; s_0] - [r_0 = 0] \\
			&amp;= \left\lfloor \frac{a_{k} b^{\left\lfloor k/2 \right\rfloor}}{q} \right\rfloor - \frac{b^{\left\lfloor k/2 \right\rfloor} - 1}{q} + [r_0 &lt; s_0] - [r = 0]. 
		\end{align*}

		
		{\bf Case 3.3} $q$ and $k$ are even. Similar to Case 1.3, we have $c_{k/2} \equiv \modd{r}{2}$ and 
		\begin{equation*}
			\sum_{0 \leq j \leq (k / 2) - 1} c_{k - j} \equiv \modd{\frac{r - c_{k/2}}{2}}{q/2}.
		\end{equation*}
		For $0 \leq c &lt; b$ such that $c \equiv \modd{r}{2}$, define $r^* (c) =(r - c)/2 \bmod{q/2}$.
		Recall that $s_0 = a_k \bmod{q/2}$. 
		Then by Lemma \ref{countinglemma}(iv), the second sum on the right-hand side of \eqref{maintheorem2eq1} is equal to
		\begin{align}
			&amp; \sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}} N_b (k/2,q/2,r^*(c), 1, a_k ) \nonumber\\
			&amp;= \sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}} \left( \frac{2(a_k - 1) (b^{(k /2) - 1} - 1)}{q} + \lfloor 2a_k / q \rfloor + [r^*(c) &lt; s_0] - [r^* (c) = 0]  \right) \nonumber\\
			&amp;= \left( \frac{2(a_k - 1) (b^{(k/2) - 1} - 1)}{q} + \frac{2(a_k - s_0)}{q}  \right) \left( \frac{b-1}{2} + [r \equiv \modd{0}{2}] \right) \nonumber\\
			&amp;\phantom{=}+  \sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}}  ([r^* (c) &lt; s_0] - [r^* (c) = 0]) \nonumber\\
			&amp;= \frac{\left( (a_k - 1) b^{(k/2) - 1} - s_0 + 1 \right) (b - 1 + 2[r \equiv \modd{0}{2}]) }{q}  \nonumber\\
			&amp;\phantom{=} +  \sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}}  ([r^* (c) &lt; s_0] - [r^* (c) = 0]). \label{maintheorem2eq8}
		\end{align}
		Since $b \equiv \modd{1}{q}$, there exists an integer $\ell \geq 1$ such that $b = \ell q + 1$.
		In addition, we have $b - 1 \equiv \modd{0}{2}$, and so if $r$ is even, then $r^*(b - 1) \equiv (r - (b - 1))/2 \equiv \modd{r/2}{q/2}$ and thus $r^*(b - 1) = r_0$ and $[r_0 = 0] = [r = 0]$.
		Then the last sum in \eqref{maintheorem2eq8} is 
		\begin{equation}\label{maintheorem2eq9}
			[r \equiv \modd{0}{2}] \left( \left[ r_0 &lt; s_0 \right] - [r = 0] \right) + \sum_{1 \leq j \leq \ell}  \sum_{\substack{ (j - 1)q \leq c &lt; jq \\ \text{$c \equiv \modd{r}{2}$}}}  ([r^*(c) &lt; s_0] - [r^* (c) = 0]).
		\end{equation}
		We see that $\{ (r - c)/2 \ |\ c \equiv \modd{r}{2}\ \text{and}\ (j - 1)q \leq c &lt; jq \}$ is a complete residue system modulo $q/2$ for any $j = 1,2, \ldots, \ell$. So 
		\begin{equation}\label{maintheorem2eq10}
			\sum_{1 \leq j \leq \ell} \sum_{\substack{ (j - 1)q \leq c &lt; jq \\ \text{$c \equiv \modd{r}{2}$}}}  ([r^* (c) &lt; s_0] - [r^* = 0]) = \sum_{1 \leq j \leq \ell} (s_0 - 1) = \frac{b - 1}{q} (s_0 - 1).
		\end{equation}
		From \eqref{maintheorem2eq8}, \eqref{maintheorem2eq9}, and \eqref{maintheorem2eq10}, we obtain that the second sum on the right-hand side of \eqref{maintheorem2eq1} is
		\begin{align*}
			&amp; \frac{(a_k - 1) (b - 1 + 2 [ r \equiv \modd{0}{2}]) b^{(k/2) - 1} - 2 (s_0 - 1) [r \equiv \modd{0}{2}]}{q} \\
			&amp;\phantom{=} + [r \equiv \modd{0}{2}] \left( \left[ r_0 &lt; s_0 \right] - [ r = 0] \right) \\
			&amp;=
			\begin{cases}
				\frac{(a_k - 1) (b - 1) b^{(k/2) - 1}}{q}, &amp;\text{if $r$ is odd;} \\
				\frac{(a_k - 1) (b + 1) b^{(k/2) - 1} - 2 (s_0 - 1) }{q} + \left[ r_0 &lt; s_0 \right] - [ r = 0], &amp;\text{if $r$ is even,}
			\end{cases}
		\end{align*}
		which proves the third and fourth cases in \eqref{maintheorem2eq6}.
		
		{\bf Case 3.4} $q$ is odd and $k$ is even.
		This case is similar to Case 3.3. 
		We have
		\begin{equation*}
			\sum_{0 \leq j \leq (k/2) - 1} c_{k - j} \equiv \modd{\left(r - c_{k/2}\right) \left( \frac{q + 1}{2} \right) }{q}.
		\end{equation*}
		For $0 \leq c &lt; b$, let $r^* (c) = ((r - c)(q + 1)/2)  \bmod{q}$.
		Since $\gcd((q + 1)/2, q) = 1$ and 
		\begin{equation*}
			\left\{ c\ |\ (j - 1)q \leq c &lt; jq \right\} \text{ is a complete residue system modulo $q$},
		\end{equation*}
		the set $\left\{ r^*(c) \ |\ (j - 1)q \leq c &lt; jq \right\}$ is also a complete residue system modulo $q$ for any $j = 1,2,\ldots, (b - 1)/q$.
		In addition, 
		\begin{equation*}
			r^* (b - 1) \equiv \frac{(r - (b - 1))(q + 1)}{2} \equiv \frac{(q + 1)r}{2} \equiv \modd{r_0}{q},
		\end{equation*}
		$[r_0 = 0] = [r = 0]$, and $(a_k b^{k/2} - s_0)/q= \lfloor a_k b^{\lfloor k/2 \rfloor }/q \rfloor$.
		Therefore
		\begin{align*}
			\sum_{\substack{n\in P_b \\\text{$ n\equiv \modd{r}{q}$}\\\text{$b^k \leq n &lt; a_kb^k$}} }1 
			&amp;= \sum_{0 \leq c &lt; b } N_b \left( k/2, q, r^*(c), 1, a_k \right) \\
			&amp;= \sum_{0 \leq c &lt; b } \left( \frac{(a_k - 1) b^{(k/2) - 1} - s_0 + 1 }{q} + [r^* (c) &lt; s_0] - [r^*(c) = 0] \right) \\
			&amp;= \frac{(a_k - 1) b^{k/2} - (s_0 - 1)b }{q}  + \sum_{0 \leq c &lt; b } \left(  [r^* (c) &lt; s_0] - [r^*(c) = 0] \right) \\
			&amp;= \frac{(a_k - 1) b^{k/2} - (s_0 - 1)b }{q} + \frac{(b - 1)}{q}(s_0 - 1) + [r_0 &lt; s_0] - [r = 0]  \\
			&amp;=  \frac{a_k b^{k/2} - s_0}{q} - \frac{b^{k/2} - 1}{q} - \frac{(b - 1)}{q} (s_0 - 1) + \frac{(b - 1)}{q} (s_0 - 1) + [r_0 &lt; s_0] - [r = 0] \\
			&amp;= \left\lfloor \frac{a_{k} b^{\left\lfloor k/2 \right\rfloor}}{q} \right\rfloor - \frac{b^{\left\lfloor k/2 \right\rfloor} - 1}{q} + [r_0 &lt; s_0] - [r = 0].
		\end{align*}
		Combining Case 3.2 and Case 3.4, we obtain the last case in \eqref{maintheorem2eq6}.
		Therefore the proof of \eqref{maintheorem2eq6} is complete. 
		
		{\bf Part 4} For each $j \in \{ 0, 1, \ldots, \left\lfloor k/2 \right\rfloor \}$, let
		\begin{equation}\label{thm2part4eq0}
			m_j = \sum_{0 \leq i \leq j} a_{k - i} b^{k - i} = (a_k a_{k - 1} \cdots a_{k-j} 0 0 \cdots 0)_b.
		\end{equation}
		For $1 \leq j \leq \left\lfloor k/2 \right\rfloor$, we will show that
		\begin{equation}\label{thm2part4eq1}
			\sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ m_{j - 1} \leq n &lt; m_j}} 1 = 
			\begin{cases}
				0, &amp;\text{if $q$ is even, $k$ is odd, and $r$ is odd;}\\
				\frac{2 a_{k - j}  b^{((k - 1)/2) - j} - 2s_j }{q}+ [r_j &lt; s_j], &amp;\text{if $q$ is even, $k$ is odd, and $r$ is even;}\\
				\frac{a_{k - j} (b - 1)b^{(k/2) - j - 1}}{q}, &amp;\text{if $q$ is even, $k$ is even, $j &lt; k/2$, and $r$ is odd;} \\
				\frac{a_{k - j} (b + 1)b^{(k/2) - j - 1} - 2s_j}{q} + \left[ r_j &lt; s_j \right], &amp;\text{if $q$ is even, $k$ is even, $j &lt; k/2$, and $r$ is even;} \\
				\left\lfloor \frac{a_{k/2}}{q} \right\rfloor + \left[ r_{k/2} &lt; s_{k/2}  \right], &amp;\text{if $q$ is even, $k$ is even, and $j = k/2$;} \\[5pt]
				\left\lfloor \frac{a_{k - j} b^{\left\lfloor k/2 \right\rfloor - j}}{q} \right\rfloor  + [r_j &lt; s_j], &amp;\text{if $q$ is odd.}
			\end{cases}
		\end{equation}
		Let $1 \leq j \leq \left \lfloor k/2 \right\rfloor$, $A$ the sum on the left-hand side of \eqref{thm2part4eq1}, 
		and $n = (c_k c_{k-1} \cdots c_1 c_0)_b$  a $b$-adic palindrome which is counted in the left-hand side of \eqref{thm2part4eq1}.
		Since $m_{j - 1} \leq n &lt; m_j$,
		\begin{equation*}
			m_{j - 1} = (a_k a_{k - 1} \cdots a_{k - (j - 1)} 0 0 \cdots 0)_b, \ \  \text{and}\ \ m_j = (a_k a_{k - 1} \cdots a_{k - j} 0 0 \cdots 0)_b,
		\end{equation*} 
		the following properties hold:
		\begin{enumerate}
			\item $c_i = c_{k - i}$ for all $i = 0, 1, 2,\ldots, k$. 
			\item $c_{k - i} = a_{k - i}$ for all $i = 0,1,2, \ldots, j - 1$.
			\item $0 \leq c_{k - j} &lt; a_{k - j}$.
			\item $0 \leq c_{k - i} &lt; b$ for all $i = j + 1, j + 2, \ldots, \lfloor k/2 \rfloor$.
		\end{enumerate}
		We see that there are only one choice for each $c_0, c_1, \ldots, c_{j - 1}, c_{k - j + 1}, c_{k - j + 2}, \ldots, c_k$ and $A$ depends on the choices of $c_i$ for $j \leq i \leq \left\lfloor k/2 \right\rfloor$.
		We divide the calculation into two cases.
		
		{\bf Case 4.1} $q$ is even and $k$ is odd. We have
		\begin{equation}\label{thm2part4eq2}
			2 \sum_{0 \leq i \leq (k - 1)/2} c_{k - i} = \sum_{0 \leq i \leq k} c_i = s_{b} (n) \equiv \modd{r}{q}.
		\end{equation}
		Then \eqref{thm2part4eq2} is impossible when $r$ is odd, so $A = 0$, which proves the first case in \eqref{thm2part4eq1}.
		Suppose $r$ is even.
		From the above properties and the definition of $r_j$, we obtain that \eqref{thm2part4eq2} is equivalent to
		\begin{equation*}
			\sum_{j \leq i \leq (k - 1)/2} c_{k - i} \equiv r/2 - \sum_{0 \leq i \leq j - 1} c_{k - i} \equiv r/2 - \sum_{0 \leq i \leq j - 1} a_{k - i} \equiv \modd{r_j}{q/2},
		\end{equation*}
		and $A$ is equal to
		\begin{align*}
			&amp;N_b \left( \frac{k - 1}{2} - j + 1, q/2, r_j, 0, a_{k - j} \right) \\
			&amp;= \frac{2 a_{k - j} \left( b^{((k - 1)/2) - j} - 1 \right)}{q} + \left\lfloor \frac{2 a_{k - j}}{q} \right \rfloor + \left[r_j \bmod{q/2} &lt; a_{k - j} \bmod{q/2} \right] \\
			&amp;= \frac{2 a_{k - j} \left( b^{((k - 1)/2) - j} - 1 \right)}{q} + \frac{2 (a_{k - j} - s_j)}{q}  + [r_j &lt; s_j] \\
			&amp;= \frac{2 a_{k - j}  b^{((k - 1)/2) - j} - 2s_j }{q}+ [r_j &lt; s_j],
		\end{align*}
		which proves the second case in \eqref{thm2part4eq1}.
		
		{\bf Case 4.2} $q$ and $k$ are odd. Similar to Case 4.1, we have
		\begin{equation*}
			\sum_{j \leq i \leq (k - 1)/2} c_{k - i} \equiv \left( \frac{q + 1}{2} \right) r - \sum_{0 \leq i \leq j - 1} a_{k - i} \equiv \modd{r_j}{q}. 
		\end{equation*}
		In addition, $a_{k - j} b^{(k - 1)/2 - j} \equiv \modd{s_j}{q}$. Therefore
		\begin{align*}
			A
			&amp;= N_b \left( \frac{k - 1}{2} - j + 1, q, r_j, 0, a_{k - j} \right) \\
			&amp;= \frac{a_{k - j} b^{((k - 1)/2) - j} - s_j}{q} + [r_j &lt; s_j] = \left\lfloor \frac{a_{k - j} b^{\left\lfloor k/2 \right\rfloor - j}}{q} \right\rfloor  + [r_j &lt; s_j].
		\end{align*}
		
		{\bf Case 4.3} $q$ and $k$ are even. Using the same method of calculation, we have $c_{k/2} \equiv \modd{r}{2}$ and
		\begin{equation*}
			\sum_{0 \leq i \leq (k / 2) - 1} c_{k - i} \equiv \modd{\frac{r - c_{k/2}}{2}}{q/2}.
		\end{equation*}
		
		{\bf Case 4.3.1} $j &lt; k/2$. We have
		\begin{equation*}
			\sum_{j \leq i \leq (k/2) - 1} c_{k - i} \equiv \frac{r - c_{k/2}}{2} - \sum_{0 \leq i \leq j - 1} c_{k - i} \equiv \modd{\frac{r - c_{k/2}}{2} - \sum_{0 \leq i \leq j - 1} a_{k - i}}{q/2}.
		\end{equation*}
		For $0 \leq c &lt; b$ and $c \equiv \modd{r}{2}$, define $r_{j}^* (c) = \left( (r - c)/2 - \sum_{0 \leq i \leq j - 1} a_{k - i} \right) \bmod{q/2}$. Then $A$ is equal to
		\begin{align}
			&amp;\sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}} N_{b} \left( (k/2) - j, q/2, r_{j}^* (c), 0, a_{k - j} \right) \nonumber\\
			&amp;= 	\sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}} \left( \frac{ 2 a_{k - j} \left( b^{(k/2) - j - 1} - 1 \right)}{q} + \left\lfloor \frac{2 a_{k - j}}{q} \right\rfloor + [r_{j}^* (c) &lt; s_j] \right) \nonumber\\
			&amp; = \left( \frac{ 2 a_{k - j} b^{(k/2) - j - 1} - 2s_j}{q} \right) \left( \frac{b - 1}{2} + [r \equiv \modd{0}{2}] \right) + \sum_{\substack{0 \leq c &lt; b \\ \text{$c \equiv \modd{r}{2}$}}} [r_{j}^* (c) &lt; s_j]. \label{thm2part4eq4} 
		\end{align}
		Similar to Case 3.3, we write $b = \ell q + 1$ for some $\ell \in \mathbb{Z}$, and obtain that 
		\begin{equation*}
				\left\{ r_j^* (c)\ |\ c \equiv \modd{r}{2} \text{ and } (i - 1)q \leq c &lt; iq \right\}
		\end{equation*}		
		is a complete residue system modulo $q/2$ for any $i = 1,2,\ldots, \ell$, and if $r$ is even, then
		\begin{equation*}
			r^*_j(b - 1) \equiv \frac{r - (b - 1)}{2} - \sum_{0\leq i \leq j - 1} a_{k - i} \equiv r/2 - \sum_{0\leq i \leq j - 1} a_{k - i} \equiv \modd{r_j}{q/2}.
		\end{equation*}
		Therefore the last sum in \eqref{thm2part4eq4} is 
		\begin{align}
			&amp;[r \equiv \modd{0}{2}] [r_j &lt; s_j] + \sum_{1 \leq i \leq \ell}  \sum_{\substack{ (i - 1)q \leq c &lt; iq \\ \text{$c \equiv \modd{r}{2}$}}}  [r^*_j (c) &lt; s_j] \nonumber\\
			&amp;= [r \equiv \modd{0}{2}] [r_j &lt; s_j] + \sum_{1 \leq i \leq \ell} s_j \nonumber\\
			&amp;=  [r \equiv \modd{0}{2}] [r_j &lt; s_j] + \frac{b - 1}{q} s_j. \label{thm2part4eq5}
		\end{align}		
		From \eqref{thm2part4eq4} and \eqref{thm2part4eq5}, we have
		\begin{align*}
			A &amp;= \frac{a_{k - j} (b - 1) b^{(k/2) - j - 1}}{q} + [r \equiv \modd{0}{2}]\left( \frac{ 2 a_{k - j} b^{(k/2) - j - 1} - 2s_j}{q} + [r_j &lt; s_j] \right) \\
			&amp;= 
			\begin{cases}
				\frac{a_{k - j} (b - 1)b^{(k/2) - j - 1}}{q}, &amp;\text{if $r \equiv \modd{1}{2}$;} \\
				\frac{a_{k - j} (b + 1)b^{(k/2) - j - 1} - 2s_j}{q} + \left[ r_j &lt; s_j \right], &amp;\text{if $r \equiv \modd{0}{2}$,} \\
			\end{cases}
		\end{align*}
		which proves the third and fourth case in \eqref{thm2part4eq1}.
		
		{\bf Case 4.3.2} $j = k/2$. Then $A$ depends only on the choices of $c_{k/2}$ and
		\begin{equation*}
			c_{k/2} \equiv r - 2 \sum_{0 \leq i \leq (k/2) - 1} c_{k - i} \equiv r - 2 \sum_{0 \leq i \leq (k/2) - 1} a_{k - i} \equiv \modd{r_{k/2}}{q}.
		\end{equation*}
		By Lemma \ref{countinglemma 2}, we obtain that
		\begin{equation*}
			A = \sum_{\substack{0 \leq c &lt; a_{k/2} \\ \text{$c \equiv \modd{r_{k/2}}{q}$}}} 1 = \left\lfloor \frac{a_{k/2}}{q} \right\rfloor + [r_{k/2} &lt; s_{k/2}],
		\end{equation*}
		which proves the fifth case in \eqref{thm2part4eq1}.
		
		{\bf Case 4.4} $q$ is odd and $k$ is even.
		There is a similarity between Case 4.3 and this case, so we skip some details.
		
		{\bf Case 4.4.1} $j &lt; k/2$. For $0 \leq c &lt; b$, define $r_j^* (c) = \left( (r - c)(q + 1)/2 - \sum_{0 \leq i \leq j - 1} a_{k - i}\right) \bmod{q}$.
		We see that $\{ r_j ^*(c) \ |\ (i - 1)q \leq c &lt; iq \}$ is a complete residue system modulo $q$ for any $i = 1,2,\ldots , (b - 1)/q$.
		In addition, $r_j^*(b - 1) = r_{j}$ and $a_{k - j} b^{k/2 - j} \equiv \modd{s_j}{q}$. We have
		\begin{equation*}
			\sum_{j \leq i \leq (k/2) - 1} c_{k - i} \equiv \modd{(r - c_{k/2})\left(\frac{q + 1}{2}\right) - \sum_{0 \leq i \leq j - 1} a_{k - i}}{q}, \ \ \text{and}
		\end{equation*}
		\begin{align*}
			A
			&amp;= \sum_{0\leq c &lt; b} N_b \left( (k/2) - j, q, r_j^* (c), 0, a_{k - j} \right) \\
			&amp;= \sum_{0\leq c &lt; b} \left( \frac{a_{k - j}  b^{(k/2) - j - 1} - s_j}{q} + [r_j ^* (c) &lt; s_j] \right) \\
			&amp;= \frac{a_{k - j} b^{(k/2) - j} - s_j b}{q} + \sum_{0 \leq c &lt; b} [r_j ^* (c) &lt; s_j] \\
			&amp;= \frac{a_{k - j} b^{(k/2) - j} - s_j}{q} - \left( \frac{b - 1}{q} \right)s_j + \left( \frac{b - 1}{q} \right)s_j + [r_j &lt; s_j] \\
			&amp;= \left\lfloor \frac{a_{k - j} b^{\left\lfloor k/2 \right\rfloor - j}}{q} \right\rfloor  + [r_j &lt; s_j].
		\end{align*}
		
		{\bf Case 4.4.2} $j = k/2$. Then $A$ depends only on the choices of $c_{k/2}$ and
		\begin{equation*}
			c_{k/2} \equiv r - 2 \sum_{0 \leq i \leq (k/2) - 1} a_{k - i} \equiv \modd{r_{k/2}}{q}.
		\end{equation*}
		By Lemma \ref{countinglemma 2}, we obtain 
		\begin{equation*}
			A
			 = \sum_{\substack{0 \leq c &lt; a_{k/2} \\ \text{$c \equiv \modd{r_{k/2}}{q}$}}} 1 = \left\lfloor \frac{a_{k/2}}{q} \right\rfloor + \left[ r_{k/2} &lt; s_{k/2} \right].
		\end{equation*}
		Combining the results in Case 4.2 and in this case, we obtain the last case in \eqref{thm2part4eq1}.
		Therefore the verification of \eqref{thm2part4eq1} is complete.
		
		{\bf Part 5} In this part, we compute the third sum on the right-hand side of \eqref{maintheorem2eq1}.
		Recall the definitions of $m^*$ and $m_j$ given in \eqref{thm2eq1} and \eqref{thm2part4eq0}, and the definitions of $m_1^{*}$, $m_2^{*}$, and $m_3^{*}$ given in the statement of this theorem.  
		We see that the third sum on the right-hand side of \eqref{maintheorem2eq1} is
		\begin{equation}\label{thm2part5eq0}
				\sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ a_k b^k \leq n &lt; m^*}} 1 = \sum_{1 \leq j \leq \lfloor k/2 \rfloor} \sum_{\substack{n \in P_b \\ \text{$n \equiv \modd{r}{q}$} \\ m_{j - 1} \leq n &lt; m_j}} 1.
		\end{equation}
		From \eqref{thm2part4eq1} and \eqref{thm2part5eq0}, we obtain that the third sum on the right-hand side of \eqref{maintheorem2eq1} is equal to
		\begin{equation}\label{thm2part5eq1}
			\begin{cases}
				0, &amp;\text{if $q$ is even, $k$ is odd, } \\
				&amp;\text{and $r$ is odd;}\\
				m_1^* - \frac{2a_{k} b^{(k - 1)/2} - 2s_0}{q} - [r_0 &lt; s_0], &amp;\text{if $q$ is even, $k$ is odd, } \\
				&amp;\text{and $r$ is even;}\\
				m_2^* - \frac{a_k (b - 1)b^{(k/2) - 1}}{q} + \left\lfloor \frac{a_{k /2}}{q} \right\rfloor + \left[ r_{k/2} &lt; s_{k/2} \right], &amp;\text{if $q$ is even, $k$ is even,}\\
				&amp;\text{and $r$ is odd;}\\
				m_3^* - \frac{a_k (b + 1)b^{(k/2) - 1} - 2s_0}{q} - [r_0 &lt; s_0] + \left\lfloor \frac{a_{k/2}}{q} \right\rfloor + \left[ r_{k/2} &lt; s_{k/2} \right], &amp;\text{if $q$ is even, $k$ is even, } \\
				&amp;\text{and $r$ is even;}\\
				\sum_{1 \leq j \leq \lfloor k/2 \rfloor} \left( \left\lfloor \frac{a_{k - j}b^{\left\lfloor k/2 \right\rfloor - j}}{q} \right\rfloor + [r_j &lt; s_j] \right), &amp;\text{if $q$ is odd.}
			\end{cases}
		\end{equation}
		
		
		{\bf Part 6} Let $L$ be the last sum in \eqref{maintheorem2eq1}. We will calculate $L$ and $A_q (m,q,r)$. 
		The only possible $b$-adic palindrome $n$ lying in the interval $[m^*, m]$ is $n = C_b (m)$.
		Therefore
		\begin{equation*}
			L = [m \geq C_b (m)][C_b (m) \equiv \modd{r}{q}].
		\end{equation*}
		If $k$ is odd, then $C_b (m) \equiv \modd{r}{q}$ if and only if 
		\begin{equation}\label{thm2part6eq1}
			2 \sum_{0 \leq j \leq (k - 1)/2} a_{k - j} = s_b \left(C_b (m)\right) \equiv \modd{r}{q}.
		\end{equation}
		Similarly, if $k$ is even, then $C_b (m) \equiv \modd{r}{q}$ if and only if 
		\begin{equation}\label{thm2part6eq2}
			2 \sum_{0 \leq j \leq (k/2) - 1} a_{k - j} + a_{k/2}= s_b \left(C_b (m)\right) \equiv \modd{r}{q}.
		\end{equation}
		If $k$ is even, then \eqref{thm2part6eq2} is equivalent to $r_{\left\lfloor k/2  \right\rfloor} = s_{\left\lfloor k/2 \right\rfloor}$.
		If $k$ is odd, $q$ is even, and $r$ is odd, then \eqref{thm2part6eq1} is not possible, and so $L = 0$. 
		In the remaining cases, the congruence \eqref{thm2part6eq1} is equivalent to $r_{\left\lfloor k/2 \right\rfloor} = s_{\left\lfloor k/2 \right\rfloor}$.
		Therefore
		\begin{equation}\label{thm2part6eq3}
			L = 
			\begin{cases}
				0, &amp;\text{if $k$ is odd, $q$ is even, and $r$ is odd;}\\
				\delta(m), &amp;\text{otherwise.}
			\end{cases}
		\end{equation}
		Therefore the desired formula for $A_b (m, q, r) $ can be obtained from \eqref{maintheorem2eq1}, \eqref{maintheorem2eq5}, \eqref{maintheorem2eq6}, \eqref{thm2part5eq1}, and \eqref{thm2part6eq3}.
		This completes the proof.
	\end{proof}
	
	 The formulas presented in Theorems \ref{thm:bcon0(q)} and \ref{maintheorem2} may look complicated. However, by examining certain special cases, the formulas are of a simpler form as shown in the corollary.
	 
	 \begin{corollary}
	 	Let $ b \geq 2 $, $ k,q \geq 1 $, and $0 \leq r&lt; q$ be integers. Then the following statements hold.
	 	\begin{itemize}
	 		\item[\emph{(i)}] Assume that $b \equiv \modd{0}{q}$. Then 
	 		\begin{equation*}
	 			A_b \left( b^k, q, r \right) = 	\left( (b/q) - [r = 0] \right) \left( \frac{b^{\left\lceil k/2 \right\rceil} + b^{\left\lfloor k/2 \right\rfloor} - 2 }{b - 1} \right)
	 		\end{equation*}
	 		\item[\emph{(ii)}] Assume that $b \equiv \modd{1}{q}$. Then
	 		\begin{equation*}
	 			A_b \left( b^k, q, r \right) = 
	 			\begin{cases}
	 				\frac{b^{\left\lceil k/2 \right \rceil} + b^{\left\lfloor k/2 \right\rfloor} - 2}{q}, &amp;\text{if $q$ is odd;} \\[3pt]
	 				\frac{(b - 1) b^{\left \lfloor (k - 1)/2 \right\rfloor}}{q}, &amp;\text{if $q$ is even and $r$ is odd;} \\[3pt]
	 				\frac{(b + 1)b^{\left \lfloor (k - 1)/2 \right\rfloor} + 2 b^{\left\lfloor k/2 \right\rfloor} - 4}{q}, &amp;\text{if $q$ and $r$ are even.}
	 			\end{cases}
	 		\end{equation*}
	 	\end{itemize}
	 \end{corollary}
	 
	 \begin{proof}
	 	We see that $C_b(b^k) = b^k + 1 &gt; b^k$, which implies that $[b^k \geq C_b (b^k)] = 0$. In addition, if $r &gt; 0$, then $\left \lceil (1 - r)/ q \right \rceil = 0$. 
	 	Then (i) follows from Theorem \ref{thm:bcon0(q)}.
	 	For (ii), let $m = b^k = (100\cdots 0)_b$ and let $m^* _1, m^* _2, m^* _3, r_j, s_j$ for each $0 \leq j \leq \lfloor k/2 \rfloor$ be defined as in Theorem \ref{maintheorem2}. Then for $0 \leq j \leq \left\lfloor k/2 \right\rfloor$, we have
	 	\begin{equation*}
	 		s_j = 
	 		\begin{cases}
	 			1, &amp;\text{if $j = 0$;}\\
	 			0, &amp;\text{if $j \neq 0$,}
	 		\end{cases}
	 	\end{equation*}
	 	\begin{equation*}
	 		[r_j &lt; s_j] = 
	 		\begin{cases}
	 			[r = 0], &amp;\text{if $j = 0$;}\\
	 			0, &amp;\text{if $j \neq 0$,}
	 		\end{cases}
	 	\end{equation*}
	 	\begin{equation*}
	 		m^*_1 = \frac{2b^{(k - 1)/2} - 2}{q} + [r = 0], \quad m^* _2 = \frac{2b^{(k - 1)/2} - 2}{q},
	 	\end{equation*}
	 	\begin{equation*}
	 		m^*_3 = \frac{(b + 1)b^{(k/2) - 1} - 2}{q}, \quad \text{and} \quad [m \geq C_b (m)] = 0.
	 	\end{equation*}
	 	From the above observation and Theorem \ref{maintheorem2}, we obtain (ii).
	 \end{proof}

	The next corollary gives a supplementary result to Col's theorems \cite{Col}. 
	Recall that if we write $f(b) = g(b) + O^\ast (h(b))$, then it means that $f(b) = g(b) + O(h(b))$ and the implied constant can be taken to be $1$.
	
	\begin{corollary}\label{corollary2}
		Let $b \geq 2$, $q \geq 1$, and $0 \leq r &lt; q$ be integers. Assume that $q$ is odd and $b \equiv \modd{1}{q}$. Then uniformly for $m \geq 1$, we have
		\begin{equation*}
			A_b (m,q,r) = \frac{1}{q} A_b (m) + O^* \left(\frac{\log m}{2 \log b} + 2 \right).
		\end{equation*}
	\end{corollary}
	
	\begin{proof}
		If $q = 1$, then $A_b (m,q,r) = A_b (m)/q$ and the result follows immediately. 
		So assume that $q \geq 2$.
		Let $m = (a_k a_{k - 1}\cdots a_1 a_0)_b$.
		By Corollary \ref{corollary1} and Theorem \ref{maintheorem2}, we obtain
		\begin{equation*}
			\frac{1}{q} A_b (m) = \frac{b^{\left\lfloor (k + 1)/2 \right\rfloor}}{q} + \sum_{0 \leq i \leq \left\lfloor \frac{k}{2}  \right\rfloor} \frac{a_{k - i} b^{\left\lfloor k/2 \right\rfloor - i}}{q} + \frac{[m \geq C_b (m)] - 2}{q} \ \ \text{and}
		\end{equation*}
		\begin{equation*}
			A_{b} (m,q,r) = \frac{b^{\left\lfloor (k+1)/2 \right\rfloor} - 1}{q} + \sum_{0 \leq j \leq \left\lfloor \frac{k}{2} \right\rfloor} \left( \left\lfloor \frac{a_{k - j}b^{\left\lfloor k/2 \right\rfloor - j}}{q} \right\rfloor + [r_j &lt; s_j] \right) - [r = 0] + \delta(m),
		\end{equation*}
		where $r_0, \ldots, r_{\left\lfloor k/2 \right\rfloor}, s_0, \ldots, s_{\left\lfloor k/2 \right\rfloor}, \delta(m)$ are defined as in Theorem \ref{maintheorem2}.
		In addition, we also have $k = \left\lfloor (\log m)/(\log b) \right\rfloor$ and $0 \leq x - \lfloor x \rfloor &lt;1$ for all $x \in \mathbb{R}$.
		If $\delta(m) = 1$, then $[m \geq C_b (m)] = 1$.
		If $\delta(m) = 0$, then $0 \leq [m \geq C_b (m)] \leq 1$.
		Therefore
		\begin{equation*}
			A_{b} (m,q,r) - \frac{1}{q} A_b (m)  \leq - (1/q) + ( (k/2) + 1) + 1 + 1/q = (k/2) + 2.
		\end{equation*}
		It is also easy to see that
		\begin{equation*}
			A_{b} (m,q,r) - \frac{1}{q} A_b (m) \geq - (1/q) - \left( (k/2) + 1 \right) - 1 + 1/q = - (k/2) - 2.
		\end{equation*}
		Hence $\left| A_{b} (m,q,r) - A_b (m)/q \right| \leq k/2 + 2 \leq (\log m)/(2 \log b) + 2$, as required.
	\end{proof}
	
	
	\section{Conclusion and open questions}
	
	We obtain exact formulas for the number of $b$-adic palindromes not exceeding a positive integer $m$ that lie in an arithmetic progression $r \bmod{q}$ when $b \equiv \modd{0,1}{q}$.
	By modifying Lemmas, we strongly believe that an analogous formula for the case $b \equiv \modd{-1}{q}$ can be obtained, but we have not proceeded to a calculation yet to avoid making this  article too lengthy. 
	We also derive an asymptotic formula for the number of $b$-adic palindrome that are at most $m$ and are congruent to $r$ modulo $q$ when $q$ is odd and $b \equiv \modd{1}{q}$ that gives an equidistribution result in residue classes modulo $q$ extending Col's result \cite{Col}, which is under the different condition $\gcd(b (b^2 - 1), q) = 1$. 
	We currently do not have sufficiently satisfactory or interesting results in the other cases.
	This leads us to some open questions.
	\begin{problem}
		What can we say about the distribution of $b$-adic palindromes in residue classes modulo $q$ when $b \not\equiv \modd{-1, 0, 1}{q}$ and $\gcd (b(b^2 - 1), q) &gt; 1$?
		Are they uniformly distributed?
	\end{problem}
	
	\begin{problem}
		Is there any nontrivial case for $b$ and $q$ that $b$-adic palindromes are not asymptotically equidistributed in residue classes modulo $q$? 
		A trivial case is, for example, when $r = 0$, $b = 10$, and $q$ is a power of $10$ where $A_b (m,q,r) = A_{10} (m,q,r) = 0$ for all $m$.
	\end{problem}
	
	\begin{problem}
		What are the necessary and sufficient conditions on $b$ and $q$ for an (asymptotic) equidistributed result?
	\end{problem}
	
	
	\section{Acknowledgments}
	
	We are grateful to the referee for his or her suggestions that improve the quality and presentation of this paper.
	Prapanpong Pongsriiam's research project is supported jointly by the Faculty of Science Silpakorn University and the National Research Council of Thailand (NRCT), grant number NRCT5-RSA63021-02. He was also supported by the Tosio Kato Fellowship given by the Mathematical Society of Japan during his visit at Nagoya University in July 2022 to July 2023. This work was started when he was in Japan and finished when he came back to Thailand. He is thankful to Professor Kohji Matsumoto for being his host professor and finding a very convenient and comfortable accommodation and office for him during his visit at Nagoya University. 
	
	\begin{thebibliography}{99}
		\bibitem{Bank} W. D. Banks, Every natural number is the sum of forty-nine palindromes, \emph{Integers} \textbf{16} (2016), Paper No. A3.
		
		\bibitem{Bank2} W. D. Banks, D. N. Hart, and M. Sakata, Almost all palindromes are composite, \emph{Math. Res. Lett.} \textbf{11} (2004), 853--868.
		
		\bibitem{Bank3}  W. D. Banks and I. Shparlinski, Prime divisors of palindromes, \emph{Period. Math. Hungar.} \textbf{51} (2005), 1--10.
		
		\bibitem{Basic} B. Ba\u{s}i\'{c}, On $d$-digit palindromes in different bases: the number of bases is unbounded, \textit{Int. J. Number Theory} \textbf{8} (2012), 1387--1390.
		
		\bibitem{Basic2} B. Ba\u{s}i\'{c}, On \lq\lq very palindromic\rq\rq sequences, \textit{J. Korean Math. Soc.} \textbf{52} (2015), 765--780.
		
		\bibitem{Cil} J. Cilleruelo, F. Luca, and L. Baxter, Every positive integer is a sum of three palindromes, \emph{Math. Comp.} \textbf{87} (2018), 3023--3055.
		
		\bibitem{CLT} J. Cilleruelo, F. Luca, and R. Tesoro, Palindromes in linear recurrence sequences, \textit{Monatsh. Math.} \textbf{171} (2013), 433--442.
		
		\bibitem{Col} S. Col, Palindromes dans les progressions arithm\'{e}tiques, \textit{Acta Arith.} \textbf{137} (2009), 1--41.
		
		\bibitem{Concrete}
		\newblock R. L. Graham, D. E. Knuth, and O. Patashnik, \emph{Concrete Mathematics: A Foundation for Computer Science},
		\newblock Second Edition, Addison--Wesley, 1994.
		
		\bibitem{Goins} E. H. Goins, Palindromes in different bases: A conjecture of J. Ernest Wilkins, \textit{Integers} \textbf{9} (2009), 725--734.
		
		\bibitem{HS} M. Harminc and R. Sot\'{a}k, Palindromic numbers in arithmetic progressions, \textit{Fibonacci Quart.} \textbf{36} (1998), 259--262.
		
		\bibitem{Korec} I. Korec, Palindromic squares for various number system bases, \emph{Math. Slovaca} \textbf{41} (1991), 261--276.
		
		\bibitem{LTo} F. Luca and A. Togb\'{e}, On binary palindromes of the form $10^n \pm1$, \textit{C. R. Math. Acad. Sci. Paris} \textbf{346} (2008), 487--489.
		
		\bibitem{Domo} D. P\'{a}lv\"{o}lgyi, Is there an arbitrarily long arithmetic progression whose members are palindromes? A question on MathOverflow. Available at \url{bit.ly/3W44hmT}.

		\bibitem{PP} P. Phunphayap and P. Pongsriiam, Reciprocal sum of palindromes, \textit{J. Integer Sequences} \textbf{22} (2019), 
		\href{https://cs.uwaterloo.ca/journals/JIS/VOL22/Pongsriiam/pong32.html}{Article 19.8.6}.
		
		\bibitem{Pong0} P. Pongsriiam, \textit{Analytic Number Theory for Beginners}, Student Mathematical Library,
		Vol.~103, American Mathematical Society, 2023.
		
		\bibitem{Pong} P. Pongsriiam, Longest arithmetic progressions of palindromes, \textit{J. Number Theory} \textbf{222} (2021), 362--375.
		
		\bibitem{PS} P. Pongsriiam and K. Subwattanachai, Exact formulas for the number of palindromes up to a given positive integer, \textit{Int. J. Math. Comput. Sci.} \textbf{14} (2019), 27--46.
		
		\bibitem{RSS} A. Rajasekaran, J. Shallit, and T. Smith, Sums of palindromes: an approach via automata, \textit{in 35th Symposium on Theoretical Aspects of Computer Science} (STACS 2018), Article no. 54, pp. 54:1--54:12.
		
		\bibitem{DS} A. J. Di Scala and M. Sombra, Intrinsic palindromes, \textit{Fibonacci Quart.} \textbf{42} (2004), 76--81.
		
		\bibitem{S} N. J. A. Sloane, The On-Line Encyclopedia of Integer Sequences, 2024, \url{https://oeis.org}.
		
		\bibitem{Tao} T. Tao, A comment on MathOverflow. Available at \url{bit.ly/3W44hmT}.
		
		\bibitem{Vepir} Vepir, Which number base contains the most palindromic numbers?, Mathematics Stack Exchange. Available at \url{bit.ly/3HCcLNR}.
	\end{thebibliography}
	
	\bigskip
	\hrule
	\bigskip
	
	\noindent 2020 {\it Mathematics Subject Classification}:
	Primary 11A63; Secondary 05A15.
	
	\noindent \emph{Keywords: } palindrome, arithmetic progression, palindromic number, digit, $b$-adic
	expansion, enumeration.
	
	\bigskip
	\hrule
	\bigskip
	
	\noindent (Concerned with sequences
\seqnum{A002113} and
\seqnum{A006995}.)
	
	
	\bigskip
	\hrule
	\bigskip
	
	\vspace*{+.1in}
	\noindent
	Received July 1 2023;
	revised versions received  April 2 2024; April 4 2024.
	Published in {\it Journal of Integer Sequences}, April 13 2024.
	
	\bigskip
	\hrule
	\bigskip
	
	\noindent
	Return to
	\htmladdnormallink{Journal of Integer Sequences home page}{https://cs.uw terloo.ca/journals/JIS/}.
	\vskip .1in
	
	
\end{document}


</pre></body></html>