## 1 Introduction

Continued fractions are very important objects both from a theoretical and an applied point of view. First of all, they allow to characterize rational numbers and quadratic irrationals over the real numbers. Indeed, a continued fraction has a finite expansion if and only if it represents a rational number and it has a periodic expansion if and only if it represents a quadratic irrational. Moreover, they provide the best approximations of real numbers and they are used in applied fields like cryptography. Thus, it has been natural to introduce them over the field of p-adic numbers $$\mathbb {Q}_p$$, with the aim of reproducing all the good properties of the classical continued fractions and exploiting them for deepening the knowledge of the p-adic numbers. Nevertheless, the definition of a good and satisfying p-adic continued fraction algorithm is still an open problem, since it is hard to find one interpretation that retrieves all the results that hold in the real case. There have been several attempts trying to emulate the standard definition in the field of real numbers, the most studied are due to Browkin [1, 2], Ruban [3] and Schneider [4]. The continued fractions introduced in Bedocchi [3] and [4] can have either a finite or periodic expansion when representing a rational number (see Browkin [5] and [6]). Moreover, the two algorithms are not periodic for all quadratic irrationals (the characterization of the periodicity for these two algorithms can be found, respectively, in Bundschuh [7] and Capuano et al. [8]). On the contrary, in Barbero et al. [1] Browkin defined a p-adic continued fraction algorithm terminating in a finite number of steps on rational numbers. However, this algorithm does not seem to be periodic on quadratic irrationals, although it is not known any example of a quadratic irrational number without periodic expansion. In fact, a full characterization for periodic continued fractions of this kind is still missing. The p-adic continued fraction expansion $$[b_0, b_1, \ldots ]$$ of $$\alpha _0\in \mathbb {Q}_p$$ provided by this algorithm, which is usually called Browkin I, is obtained by iterating the following steps:

\begin{aligned} {\left\{ \begin{array}{ll} b_n=s(\alpha _n)\\ \alpha _{n+1}=\frac{1}{\alpha _n-b_n}, \end{array}\right. } \quad \forall n \ge 0, \end{aligned}
(1)

where $$s: \mathbb {Q}_p\rightarrow \mathbb {Q}$$ is a function that replaces the role of the floor function in the classical continued fractions over $$\mathbb R$$. For a p-adic number $$\alpha =\sum \nolimits _{n=-r}^{+\infty } a_np^n\in \mathbb {Q}_p$$, with $$r\in \mathbb {Z}$$ and $$a_n\in \{-\frac{p-1}{2},\ldots ,\frac{p-1}{2}\}$$, the function s is defined as

\begin{aligned} s(\alpha )=\sum \limits _{n=-r}^{0} a_np^n\in \mathbb {Q}, \end{aligned}

with $$s(\alpha )=0$$ for $$r<0$$.

This continued fraction is very similar to the one defined in Bedocchi [3], but here the representatives are taken in $$\{-\frac{p-1}{2},\ldots ,\frac{p-1}{2}\}$$ instead of the canonical ones $$\{0,\ldots , p-1 \}$$. In the same paper, Browkin showed that this algorithm terminates in a finite number of steps if and only if $$\alpha \in \mathbb {Q}$$. More than 20 years later, Browkin introduced in Barbero et al. [2] another p-adic continued fractions algorithm, using a different floor function in combination with the s function, with the aim of obtaining better results on the behaviour of the algorithm over quadratic irrationals. For $$\alpha =\sum \nolimits _{n=-r}^{+\infty } a_np^n\in \mathbb {Q}_p$$, with $$r\in \mathbb {Z}$$ and $$a_n\in \{-\frac{p-1}{2},\ldots ,\frac{p-1}{2}\}$$, the new floor function is defined as

\begin{aligned} t(\alpha )=\sum \limits _{n=-r}^{-1}a_np^n, \end{aligned}

with $$t(\alpha )=0$$ for $$r\le 0$$.

The new algorithm proposed by Browkin, which is usually called Browkin II, works as follows: starting from $$\alpha _0\in \mathbb {Q}_p$$ the partial quotients of the p-adic continued fraction are computed for $$n \ge 0$$ as

\begin{aligned} {\left\{ \begin{array}{ll} b_n=s(\alpha _n) \ \ \ \ \ {} &{} if \ n \ even \\ b_n=t(\alpha _n) &{} if \ n \ odd \ and \ v_p(\alpha _n-t(\alpha _n))= 0\\ b_n=t(\alpha _n)-sign(t(\alpha _n)) &{} if \ n \ odd \ and \ v_p(\alpha _n-t(\alpha _n))\ne 0\\ \alpha _{n+1}=\frac{1}{\alpha _n-b_n}. \end{array}\right. } \end{aligned}
(2)

Therefore, this algorithm produces the continued fraction expansion of a p-adic number by alternating the use of the function s and the function t, eventually adjusted with the sign function. This definition arises naturally in order to fulfill a p-adic convergence condition proved in [2, Lemma 1]. Indeed, the convergence of Browkin I is essentially due to the fact that the partial quotients have all negative p-adic valuation (except for the first one). In [2, Lemma 1], Browkin proved that this condition can be weakened. In particular, he proved that it is sufficient to have negative p-adic valuation for partial quotients with odd index and null p-adic valuation for partial quotients with even index. Thus, the alternating use of the functions s and t is a way to obtain a continued fraction with such partial quotients. Barbero, Cerruti and the first author [9] proved that also this second algorithm terminates in a finite number of steps on each rational number. The same authors proved in [10] that this result is still true when the algorithm is performed using the canonical representatives in $$\{0,\ldots , p-1 \}$$. Moreover, in [9] and [2], it has been observed that Browkin II behaves better than Browkin I on quadratic irrationals. In particular, it appears to be periodic on more square roots and in general periods are shorter than those of the expansions produced by Browkin I. The periodicity properties of Browkin I have been well-studied (see, e.g., [10,11,12,13,14,15,16,17]), but only few things are known about Browkin II, due to the complexity of this algorithm that uses alternately different functions. However, the study of the periodicity of both algorithms is fundamental for understanding how to design more performing p-adic continued fraction algorithms. For these reasons, in this paper we are interested in studying the periodicity properties of Browkin II p-adic continued fractions.

The paper is organized as follows. In Sect. 2, we recall some useful definitions and we adapt them to Browkin II. In Sect. 3, we first give a necessary condition for the pure periodicity of Browkin II, obtaining results similar to the ones proved by Bedocchi [11] for Browkin I. Moreover, we prove that if $$\sqrt{D}$$ exists in $$\mathbb Q_p$$ and has a periodic expansion by means of Browkin II, then the preperiod has length either 1 or even. Finally, in Sect. 4, we prove that there exist infinitely many square roots of integers having a periodic expansion with period of length 4, answering to a problem left open by Browkin in [2]. We also explicitly provide a family of square roots having such a periodic expansion.

## 2 Preliminaries

From now on, consider p to be an odd prime. Let us denote by $$v_p(\cdot )$$ and $$|\cdot |_p$$ the p-adic valuation and the p-adic norm. Moreover, we denote by $$(A_n)_{n \ge 0}$$ and $$(B_n)_{n \ge 0}$$ the sequences obtained by the usual recurrence formulas for the convergents of a continued fraction:

\begin{aligned} {\left\{ \begin{array}{ll} A_0=b_0\\ A_1=b_1b_0+1\\ A_n=b_nA_{n-1}+A_{n-2} \text { for } n \ge 2, \end{array}\right. } {\left\{ \begin{array}{ll} B_0=1\\ B_1=b_1\\ B_n=b_nB_{n-1}+B_{n-2} \text { for } n \ge 2, \end{array}\right. } \end{aligned}

so that

\begin{aligned} \frac{A_n}{B_n}=[b_0,b_1,\ldots ,b_n]=b_0+\frac{1}{b_1+\frac{1}{\ddots + \frac{1}{b_n}}}. \end{aligned}

Note that, in this case $$A_n$$ and $$B_n$$ are elements of $$\mathbb Z\left[ \frac{1}{p}\right]$$ for all $$n\in \mathbb {N}$$.

### Example 1

Let us consider $$\alpha _0 = \frac{22}{7} \in \mathbb Q_5$$. Applying Browkin II we obtain:

\begin{aligned} \alpha _0&= \frac{22}{7} = 1 - 1 \cdot 5 + 1 \cdot 5^2 + \ldots ,&\ b_0&= s(\alpha _0) = 1, \ {}&\\ \alpha _1&= \frac{7}{15} = -1 \cdot 5^{-1} - 1 +2 \cdot 5 + \ldots ,&b_1&= t(\alpha _1) = -\frac{1}{5},&\\ \alpha _2&= \frac{3}{2} = -1 -2 \cdot 5 - 2 \cdot 5^2+ \ldots ,&b_2&= s(\alpha _2) = -1,&\\ \alpha _3&= \frac{2}{5},&b_3&= t(\alpha _3) - sign(t(\alpha _3)) = -\frac{3}{5},&\\ \alpha _4&= 1,&b_4&= s(\alpha _4) = 1,&\end{aligned}

so that we have $$\frac{22}{7} = \left[ 1, -\frac{1}{5}, -1, -\frac{3}{5}, 1 \right]$$. Thus, using the recurrence formulas, we have

\begin{aligned} \left\{ \begin{aligned} A_0&= 1,&\ A_1&= \frac{4}{5},&\ A_2&= \frac{1}{5},&\ A_3&= \frac{17}{25},&\ A_4&= \frac{22}{25}, \\B_0&= 1,&B_1&= -\frac{1}{5},&B_2&= \frac{6}{5},&B_3&= -\frac{23}{25},&B_4&= \frac{7}{25}, \end{aligned} \right. \end{aligned}

and the sequence of convergents is:

\begin{aligned} 1, -4, \frac{1}{6}, -\frac{17}{23}, \frac{22}{7}. \end{aligned}

We also define the following sets:

\begin{aligned} J_p=\left\{ \frac{a_0}{p^n}\ \bigg {|} \ n\in \mathbb {N}, \ -\frac{p^{n+1}}{2}< a_0 < \frac{p^{n+1}}{2} \right\} =\mathbb {Z}\left[ \frac{1}{p}\right] \cap \left( -\frac{p}{2},\frac{p}{2}\right) , \end{aligned}

and

\begin{aligned} K_p=\left\{ \frac{a_0}{p^n}\ \bigg {|} \ n\ge 1, \ -\frac{p^n}{2}< a_0 < \frac{p^{n}}{2}\right\} =\mathbb {Z}\left[ \frac{1}{p}\right] \cap \left( -\frac{1}{2},\frac{1}{2}\right) . \end{aligned}

The following lemma is due to Bedocchi.

### Lemma 2

(Lemma 2.2, [11]) For all $$a,b\in J_p$$, with $$a\ne b$$, we have $$v_p(a-b)\le 0$$.

In the following lemma we prove a similar result for the function t and the set $$K_p$$.

### Lemma 3

Let $$\alpha =\sum \limits _{n=-r}^{+\infty }a_np^n\in \mathbb {Q}_p$$, with $$r\in \mathbb {Z}$$ and $$a_n\in \{-\frac{p-1}{2},\ldots ,\frac{p-1}{2} \}$$ for all $$n\in \mathbb {N}$$. Then

\begin{aligned} \Big |t(\alpha )\Big |<\frac{1}{2}, \end{aligned}

where $$|\cdot |$$ is the Euclidean norm.

### Proof

If $$r\le 0$$ then $$|t(\alpha )|=0<\frac{1}{2}$$ and the claim holds. When $$r > 0$$, then

\begin{aligned} t(\alpha )=t\left( \sum \limits _{n=-r}^{+\infty }a_np^n\right) =\sum \limits _{n=-r}^{-1}a_np^n, \end{aligned}

and we have

\begin{aligned} \Big |t(\alpha )\Big |&=\Bigg |\sum \limits _{n=-r}^{-1}a_np^n\Bigg |\le \frac{p-1}{2}\Bigg |\sum \limits _{n=-r}^{-1}p^n\Bigg |=\frac{1}{2} \cdot \frac{(p-1)(1+p+\cdots +p^{r-1})}{p^r}=\frac{1}{2}\cdot \frac{p^r-1}{p^r}<\frac{1}{2}, \end{aligned}

and the thesis follows.

Now we prove the analogue of Lemma 2 for the set $$K_p$$.

### Lemma 4

For all $$a,b\in K_p$$, with $$a\ne b$$, we have $$v_p(a-b)< 0$$.

### Proof

Let us write $$a=\frac{a_0}{p^n}$$ and $$b=\frac{b_0}{p^m}$$, with $$v_p(a_0)=v_p(b_0)=0$$. We can notice that $$n,m\ge 1$$ since $$v_p(a)$$ and $$v_p(b)$$ are both negative. If $$n\ne m$$, we may suppose $$n>m$$ without loss of generality, and we get

\begin{aligned} v_p(a-b)&=v_p\Big (\frac{a_0}{p^n}-\frac{b_0}{p^m} \Big )=v_p\Big (\frac{a_0-b_0p^{n-m}}{p^n}\Big )\\&=v_p(a_0-b_0p^{n-m})-v_p(p^n)=(n-m)-n=-m<0. \end{aligned}

If $$n=m$$, then

\begin{aligned} v_p(a-b)=v_p\Big (\frac{a_0}{p^n}-\frac{b_0}{p^n} \Big )=v_p\Big (\frac{a_0-b_0}{p^n}\Big )=v_p(a_0-b_0)-n. \end{aligned}

Since $$|a_0-b_0|<p^n$$, necessarily $$v_p(a_0-b_0)<n$$, hence

\begin{aligned} v_p(a-b)=v_p(a_0-b_0)-n<0, \end{aligned}

and this concludes the proof.

Lemma 3 and Lemma 4 allow us to get useful results on the periodicity of Browkin II.

### Remark 5

In [1] it has been proved that, for Browkin I, the valuations of the $$A_n$$’s and $$B_n$$’s are computed as

\begin{aligned} \begin{aligned} v_p(A_n)&=v_p(b_0)+v_p(b_1)+\cdots +v_p(b_n),\\ v_p(B_n)&=v_p(b_1)+v_p(b_2)+\cdots +v_p(b_n), \end{aligned} \end{aligned}
(3)

or, equivalently,

\begin{aligned} \begin{aligned} |A_n|_p&=|b_0|_p|b_1|_p\ldots |b_n|_p,\\ |B_n|_p&=|b_1|_p|b_2|_p\ldots |b_n|_p. \end{aligned} \end{aligned}
(4)

This result is proved by induction using the fact that, for all $$n\ge 0$$,

\begin{aligned} v_p(b_{n+2}B_{n+1})<v_p(B_n). \end{aligned}

The latter condition is true also for Browkin II, (see [2], Lemma 1), hence Eqns. (3) and (4) also hold for Browkin II.

## 3 Periodicity of Browkin’s second algorithm

Bedocchi [11, 12] was able to provide some results on the periodicity of Browkin I. First of all, he obtained an analogue of the Galois’ Theorem for classical continued fractions, which provide a characterization of the pure periodicity by means of reduced quadratic irrational (see, e.g., [18]). Then, he focused on the length of the preperiod and the period for square roots of integers. In particular, he proved that if $$\sqrt{D}\in \mathbb {Q}_p$$ has a periodic expansion by means of Browkin I, then the preperiod must have length two and the period can not have length one.

In this section we deepen the study of Browkin II. In particular, we obtain an analogue of the Galois’ Theorem and we prove that if $$\sqrt{D}\in \mathbb {Q}_p$$ has a periodic expansion by means of Browkin II, then the preperiod must have length either 1 or even. Let us notice that, by construction of Browkin II, the length of the period of a continued fraction obtained by this algorithm must be even.

### Remark 6

Let us recall that, if D is an integer which is not a perfect square, then there exists $$\alpha \in \mathbb Q_p$$ such that $$\alpha ^2 = D$$ if and only if D is a quadratic residue modulo p. In this last case, there exist $$z \in \{0, \ldots \frac{p-1}{2}\}$$ such that $$z^2 \equiv D \pmod p$$ and $$p-z \in \{\frac{p-1}{2},\ldots ,p-1 \}$$ is the other element with this property. Now, both this values can be lifted to elements in $$\mathbb Q_p$$; hence we call $$\sqrt{D}$$ the p-adic number whose expansion starts with z and $$-\sqrt{D}$$ the other one, i.e. the one starting with $$p-z$$.

### Remark 7

If a p-adic number $$\alpha$$ has a periodic continued fraction, using a standard argument it is possible to see that it is a quadratic irrational [11, Remark 2.7.5]. It means that $$\alpha$$ is the root of an irreducible polynomial of degree 2 over $$\mathbb {Q}$$. We denote by $$\overline{\alpha }$$, and we call it the conjugate of $$\alpha$$, the second root of this polynomial, that lies inside $$\mathbb {Q}_p$$.

In the following two theorems we obtain a partial result in the spirit of Galois’ Theorem also for Browkin II.

### Theorem 8

If $$\alpha \in \mathbb {Q}_p$$ has a purely periodic continued fraction expansion $$\alpha =[\overline{b_0,\ldots ,b_{k-1}}]$$ with Browkin II, then

\begin{aligned} |\alpha |_p=1, \ \ |\overline{\alpha }|_p<1. \end{aligned}

### Proof

To prove the first result, we adapt the technique of [11, Proposition 3.1] for the case of Browkin II.

Let us notice that, by pure periodicity,

\begin{aligned} v_p(\alpha )=v_p(b_0)=v_p(b_k)=0, \end{aligned}

then $$|\alpha |_p=1$$. If we set, for all $$n\in \mathbb {N}$$,

\begin{aligned} \alpha _n=[b_n,b_{n+1},\ldots ,b_{n+k-1},\alpha _n]=[b_0',b_1',\ldots ,b_{k-1}',\alpha _n], \end{aligned}

and $$\dfrac{A_n'}{B_n'}$$ are its convergents, then:

\begin{aligned} B_{k-1}'\alpha _n^2+(B_{k-2}'-A_{k-1}')\alpha _n-A_{k-2}'=0. \end{aligned}

By (4),

\begin{aligned} |\alpha _n\overline{\alpha }_n|_p=\left|\frac{A_{k-2}'}{B_{k-1}'}\right|_p=\frac{|b_0'|_p|b_1'|_p\ldots |b_{k-2}'|_p}{|b_1'|_p\ldots |b_{k-2}'|_p|b_{k-1}'|_p}=\frac{|b_0'|_p}{|b_{k-1}'|_p}=\frac{|b_n|_p}{|b_{n+k-1}|_p}, \end{aligned}

from which we get

\begin{aligned} |\overline{\alpha }_n|_p=\frac{1}{|b_{n+k-1}|_p}. \end{aligned}

Since $$k-1$$ is odd, then:

\begin{aligned} {\left\{ \begin{array}{ll} |\overline{\alpha }_n|_p=1 \ \ \ \ if \ n \ odd \\ |\overline{\alpha }_n|_p<1 \ \ \ \ if \ n \ even , \end{array}\right. } \end{aligned}

and, in particular, for $$n=0$$, $$|\overline{\alpha }|_p=|\overline{\alpha }_0|_p<1$$.

In light of Theorem 8, it is meaningful to wonder which are (and if there exist) the p-adic numbers satisfying the necessary condition for pure periodicity.

### Proposition 9

Let $$\alpha =a+\sqrt{D}\in \mathbb {Q}_p$$, with $$a, D\in \mathbb {Z}$$, D not a square,

\begin{aligned} \sqrt{D}=a_0+a_1p+a_2p^2+\ldots . \end{aligned}

Then $$|\alpha |_p=1$$ and $$|\overline{\alpha }|_p<1$$ if and only if $$a\equiv a_0 \mod p$$.

### Proof

Let us notice that $$a_0\not \equiv 0 \mod p$$ and, if $$|\alpha |_p=1$$ and $$|\overline{\alpha }|_p<1$$, then

\begin{aligned} v_p(\overline{\alpha })=v_p(a-a_0-a_1p-a_2p^2-\ldots )>1; \end{aligned}

it means that $$a-a_0\equiv 0 \mod p$$, so $$a\equiv a_0 \mod p$$.

Viceversa, if $$a\equiv a_0 \mod p$$, then $$a=a_0+kp$$, for some $$k\in \mathbb {Z}$$. Therefore,

\begin{aligned} v_p(\alpha )=v_p(a+\sqrt{D})=v_p(2a_0+(k+a_1)p+\ldots )=0, \end{aligned}

since $$2a_0\not \equiv 0 \mod p$$, for $$p\ne 2$$; moreover

\begin{aligned} v_p(\overline{\alpha })=v_p(a-\sqrt{D})=v_p((k-a_1)p+\ldots )>0. \end{aligned}

Hence, in this case, $$|\alpha |_p=1$$ and $$|\overline{\alpha }|_p<1.$$

The converse of Theorem 8 is not true and the best that one can prove is stated in the following theorem.

### Theorem 10

Consider $$\alpha \in \mathbb {Q}_p$$ with periodic Browkin II expansion

\begin{aligned} \alpha =[b_0,b_1,\ldots ,b_{h-1},\overline{b_h,\ldots ,b_{h+k-1}}]. \end{aligned}

If

\begin{aligned} |\alpha |_p=1, \ \ |\overline{\alpha }|_p<1, \end{aligned}

then the preperiod length can not be odd.

### Proof

Let us notice that, by the hypothesis and the construction of Browkin II, the period length k is even and, for all $$j\in \mathbb {N}$$,

\begin{aligned} |\alpha |_p&=|\alpha _{2j}|_p=1,\\ v_p(\alpha )&=v_p(b_0)=v_p(b_{2j})=0. \end{aligned}

Moreover,

\begin{aligned} |\overline{\alpha }_0|_p&=|\overline{\alpha }|_p<1,\\ v_p(\overline{\alpha }_0)&=v_p(\overline{\alpha })>0, \end{aligned}

and it follows that:

\begin{aligned} v_p(\overline{\alpha }_1)&=v_p\Big ( \frac{1}{\overline{\alpha }_0 - b_0}\Big )=-v_p(\overline{\alpha }_0 - b_0)=-v_p(b_0)=0,\\ v_p(\overline{\alpha }_2)&=v_p\Big ( \frac{1}{\overline{\alpha }_1 - b_1}\Big )=-v_p(\overline{\alpha }_1 - b_1)=-v_p(b_1)>0. \end{aligned}

Hence, the p-adic absolute value of each complete quotient is, for all $$j \in \mathbb {N}$$,

\begin{aligned} |\alpha |_p&=1, \ {}&|\alpha _{2j+1}|_p&>1, \ {}&|\alpha _{2j}|_p&=1, \\ |\overline{\alpha }|_p&<1,&|\overline{\alpha }_{2j+1}|_p&=1,&|\overline{\alpha }_{2j}|_p&<1. \end{aligned}

Since $$\alpha$$ has a periodic expansion,

\begin{aligned} \frac{1}{\alpha _{h-1}-b_{h-1}}=\alpha _h=\alpha _{h+k}=\frac{1}{\alpha _{h+k-1}-b_{h+k-1}}. \end{aligned}

So we obtain:

\begin{aligned} |\alpha _{h-1}-\alpha _{h+k-1}|_p=|b_{h-1}-b_{h+k-1}|_p, \end{aligned}

and, analogously,

\begin{aligned} |\overline{\alpha }_{h-1}-\overline{\alpha }_{h+k-1}|_p=|b_{h-1}-b_{h+k-1}|_p. \end{aligned}

By contradiction, if the preperiod length h is odd, both $$h-1$$ and $$h+k-1$$ are even. Then $$v_p(\overline{\alpha }_{h-1})>0$$ and $$v_p(\overline{\alpha }_{h+k-1})>0$$, so:

\begin{aligned} v_p(b_{h-1}-b_{h+k-1})_p&=v_p(\overline{\alpha }_{h-1}-\overline{\alpha }_{h+k-1})\ge \\&\ge \min \{v_p(\overline{\alpha }_{h-1}),v_p(\overline{\alpha }_{h+k-1}) \}>0. \end{aligned}

By Lemma 2, we have that $$b_{h-1}=b_{h+k-1}$$ and the claim is proved.

### Remark 11

In the proof of Theorem 10 we obtained that, for h odd, $$b_{h+k}=b_{h}$$ implies $$b_{h+k-1}=b_{h-1}$$. This is done by using Lemma 2 of Bedocchi for the function s. In the first section we proved a similar result for the second function t, that is Lemma 4. Lemma 4 allows us to get the implication from $$b_{h+k}=b_{h}$$ to $$b_{h+k-1}=b_{h-1}$$ also for h even, but only in the case where the odd partial quotients are obtained using the floor function t without the sign. In fact, in this case, if the length h of the preperiodic part is even, then both $$h-1$$ and $$h+k-1$$ are odd. This implies that $$v_p(\overline{\alpha }_{h-1})=0$$ and $$v_p(\overline{\alpha }_{h+k-1})=0$$. Therefore, if $$b_{h-1}=t(\alpha _{h-1})$$ and $$b_{h+k-1}=t(\alpha _{h+k-1})$$, then $$b_{h-1},b_{h+k-1}\in K_p$$. Arguing as in the proof of Theorem 10 for h odd, we get

\begin{aligned} v_p(b_{h-1}-b_{h+k-1})_p&=v_p(\overline{\alpha }_{h-1}-\overline{\alpha }_{h+k-1})\ge \\&\ge \min \{v_p(\overline{\alpha }_{h-1}),v_p(\overline{\alpha }_{h+k-1}) \}\ge 0. \end{aligned}

We conclude by Lemma 4 that $$b_{h-1}=b_{h+k-1}$$ also when h is even.

The problem with Browkin II is that, for some odd $$n\in \mathbb {N}$$,

\begin{aligned} b_n=t(\alpha _n)-sign(t(\alpha _n)). \end{aligned}

This happens when $$\alpha _n$$ has not the constant term, in order to always recover a partial quotient with null p-adic valuation. In the following example we see that this case can actually occur.

### Example 12

Let us consider

\begin{aligned} \sqrt{30}=3-3\cdot 7+\ldots \in \mathbb {Q}_7, \end{aligned}

then the expansion of $$\alpha =\sqrt{30}+3$$ is

\begin{aligned} \sqrt{30}+3=\left[ -1, \frac{3}{7}, 3, \frac{2}{7},\overline{1, \frac{2}{7}, -2, \frac{3}{7}, 1, \frac{2}{7}, 2, \frac{1}{7}, -1, -\frac{5}{7}}\right] , \end{aligned}

that is not purely periodic and has preperiod 4. Notice that the 7–adic number $$\alpha$$ satistfies the hypothesis of Theorem 10 since

\begin{aligned} v_7\Big (3+\sqrt{30}\Big )&=0,\\ v_7\Big (3-\sqrt{30}\Big )&=v_7\Big (-3\cdot 7+\ldots \Big )>0. \end{aligned}

In this case we can not make the step backward from $$b_4=b_{14}$$ to $$b_3=b_{13}$$ since

\begin{aligned} b_3&=t(\alpha _3)=\frac{2}{7},\\ b_{13}&=t(\alpha _{13})-sign(t(\alpha _{13}))=\frac{2}{7}-1=-\frac{5}{7}. \end{aligned}

In fact in the generation of $$b_{13}$$ it is used the sign function along with the t function.

In Remark 11 and Example 12, we have observed that the converse of Theorem 8 holds whenever the function sign does not appear during the generation of the even partial quotients $$b_h$$ and $$b_{h+k}$$, or whenever they use the same function sign. It would be interesting, then, to understand for which of the quadratic irrationals of Theorem 10 these cases always occur, in order to prove an explicit characterization of the pure periodicity of Browkin II.

Now we investigate the length of the preperiod of Browkin II expansions. In order to do that, we first introduce an algorithm that is a slight modification of Browkin II.

### Definition 13

(Browkin II*) We call Browkin II* the algorithm where the role of the functions s and t is switched. Starting from $$\alpha _0\in \mathbb {Q}_p$$, with $$v_p(\alpha _0)<0$$, the partial quotients of the p-adic continued fraction expansion are obtained for $$n \ge 0$$ by

\begin{aligned} {\left\{ \begin{array}{ll} b_n=s(\alpha _n) \ \ \ \ \ {} &{} if \ n \ odd \\ b_n=t(\alpha _n) &{} if \ n \ even \ and \ v_p(\alpha _n-t(\alpha _n))= 0\\ b_n=t(\alpha _n)-sign(t(\alpha _n)) &{} if \ n \ even \ and \ v_p(\alpha _n-t(\alpha _n))\ne 0\\ \alpha _{n+1}=\frac{1}{\alpha _n-b_n}. \end{array}\right. } \end{aligned}
(5)

The p-adic convergence of any continued fraction of this kind is guaranteed. In fact, every infinite continued fraction $$[b_0,b_1,b_2,\ldots ]$$ can be written as $$b_0+\frac{1}{\alpha }$$, where $$\alpha =[b_1,b_2,\ldots ]\in \mathbb {Q}_p$$ is obtained by Browkin II. It is not hard to see that the observations in Remark 5 hold also for Browkin II*, so the valuations of the convergents can be computed as in (3) and (4).

Using the same argument of Theorem 8 and Theorem 10, adapting it by switching the even and the odd steps, it is possible to prove two analogous theorems also for Browkin II*.

### Theorem 14

If $$\alpha \in \mathbb {Q}_p$$ has a purely periodic continued fraction expansion $$\alpha =[\overline{b_0,\ldots ,b_{k-1}}]$$ with Browkin II*, then

\begin{aligned} v_p(\alpha )<0, \ \ v_p(\overline{\alpha })=0. \end{aligned}

### Theorem 15

Let $$\alpha \in \mathbb {Q}_p$$ with periodic Browkin II* expansion

\begin{aligned} \alpha =[b_0,b_1,\ldots ,b_{h-1},\overline{b_h,\ldots ,b_{h+k-1}}]. \end{aligned}

Then, if

\begin{aligned} v_p(\alpha )<0, \ \ v_p(\overline{\alpha })=0, \end{aligned}

the preperiod length can not be even.

### Example 16

Under these hypotheses, Theorem 15 is the best we can obtain as a converse of Theorem 14. In fact, if we consider the expansion of $$\alpha =\frac{2+\sqrt{79}}{75}$$ in $$\mathbb {Q}_5$$ is

\begin{aligned} \frac{2+\sqrt{79}}{75}=\Big [&-\frac{7}{25}, 1, \frac{2}{5}, 2, -\frac{2}{5}, 1, \frac{1}{5}, 2, -\frac{4}{25}, 2, \frac{1}{5}, 1, -\frac{2}{5},\\&2, \frac{2}{5}, \overline{1, -\frac{7}{25}, -1, \frac{1}{5}, 2, \frac{9}{25}, -1, -\frac{3}{5}}\Big ] , \end{aligned}

that is not purely periodic and has preperiod 15. Notice that $$\alpha$$ satistfies the hypothesis of Theorem 15 since starting from

\begin{aligned} \sqrt{79}=2+2\cdot 5^2+5^3+\ldots \in \mathbb {Q}_5, \end{aligned}

then:

\begin{aligned} v_5\Big (\frac{2+\sqrt{79}}{75}\Big )&=v_5(2+\sqrt{79})-v_5(75)=v_p(4+\ldots )-2=-2<0,\\ v_5\Big (\frac{2-\sqrt{79}}{75}\Big )&=v_5(2-\sqrt{79})-v_5(75)=v_5(2\cdot 5^2+5^3+\ldots )-2=0. \end{aligned}

As consequence of the previous results, we are able to characterize the length of the preperiods for square roots of integers that have a periodic representation by means of Browkin II.

### Proposition 17

Let $$\sqrt{D}$$ be defined in $$\mathbb {Q}_p$$, with $$D\in \mathbb {Z}$$ not a square; then, if $$\sqrt{D}$$ has a periodic continued fraction with Browkin II, the preperiod has length either 1 or even.

### Proof

Notice that $$\alpha =\sqrt{D}$$ can not have purely periodic continued fraction, by Theorem 8. We can then write it as

\begin{aligned} \alpha =b_0+\frac{1}{\alpha _1}. \end{aligned}

Since $$\alpha$$ has a periodic continued fraction, also $$\alpha _1$$ has periodic continued fraction. We are going to show that:

\begin{aligned} i) \ \ v_p(\alpha _1)=v_p\Big (\frac{1}{\alpha -b_0} \Big )=-v_p(\alpha -b_0)<0,\\ ii) \ \ v_p(\overline{\alpha }_1)=v_p\Big (\frac{1}{\overline{\alpha }-b_0} \Big )=-v_p(\overline{\alpha }-b_0)=0. \end{aligned}

Notice that i) is satisfied since $$s(\alpha )=b_0$$ and $$v_p(\alpha -b_0)>0$$. Since $$\overline{\alpha }=-\sqrt{D}$$, then

\begin{aligned} \overline{\alpha }=-b_0+a'_1p+a_2'p^2+\ldots . \end{aligned}

Now, $$v_p(\overline{\alpha }-b_0)=0$$ if and only if $$b_0\ne -b_0$$, that is $$2b_0\ne 0$$. This is always the case for $$p\ne 2$$, so, by Theorem 15, $$\alpha _1$$ can not have an even preperiod length. So $$\alpha$$ has either preperiod of length 1 or of even length, as wanted.

## 4 Some periodic expansions

In [2], Browkin characterized some expansions for square roots of integers provided by Browkin II that have period 2 and 4. Through this construction, he proved the existence of infinitely many square roots of integers with periodic expansion of period 2, similarly to what Bedocchi proved in [12] for Browkin I.

However, Browkin was not able to prove that the expansions having period of length 4 that he provided were infinitely many, leaving open the problem of proving the existence of infinitely many square roots of integers having a periodic Browkin II expansion with period of length 4. Here we prove this result by constructing, for each prime p, an infinite class of square roots that have a periodic Browkin II continued fraction with period of length 4 in $$\mathbb {Q}_p$$. Similar families of continued fractions have been constructed also in [12] and [13] for Browkin I, with periods of length 2, 4 and 6.

### Theorem 18

Given $$D = \frac{1 - p^t}{(1-p)^2} \cdot p^2$$, for any integer $$t \ge 2$$, then

\begin{aligned} \pm \sqrt{D} = \left[ 0, \pm \frac{1}{p}, \overline{\mp 1, \mp \frac{2(p^{t-1}-1)}{(p-1)p^{t-1}}, \mp 1, \pm \frac{2}{p}}\right] . \end{aligned}

### Proof

In the following, we suppose $$p = 4k + 1$$, the proof for the case $$p = 4k - 1$$ is similar.

From [12, Eq. 2.1], it follows that

\begin{aligned} \sqrt{D} = p(1 + p + \ldots + p^{t-1}) + Ap^{t+1}, \end{aligned}

where

\begin{aligned} A = -\frac{p-1}{2} + p -\frac{p-1}{2} p^2 + p^3 - \ldots - \frac{p-1}{2}p^{t-1} + A' p^t, \end{aligned}

for a certain $$A'\in \mathbb {Q}_p$$ with $$v_p(A') = 0$$ and assuming t odd (a similar result holds for t even). Thus, considering $$\alpha _0 = \sqrt{D}$$, we immediately get $$b_0 = s(\alpha _0) = 0$$. Applying Browkin II, we obtain

\begin{aligned} \alpha _1 = \frac{\sqrt{D}}{D} = \frac{1}{p} - 1 + \frac{A p^{t+1}}{q\cdot p^2}, \end{aligned}

where $$q = \frac{1-p^t}{16k^2}$$, and so $$b_1 = t(\alpha _1) = \frac{1}{p}$$. The next complete quotient is

\begin{aligned} \alpha _2 = \frac{\sqrt{D} + qp}{1-q} = \frac{(2 - p)(1 - p^t) + A (p-1)^2 p^t}{p^{t-1}+p-2}. \end{aligned}

Since

\begin{aligned} \frac{1}{p^{t-1}+p-2} = \frac{p-1}{2} + \ldots \end{aligned}

we have $$b_2 = s(\alpha _2) = -1$$. In the next step, we have

\begin{aligned} \alpha _3&= \frac{p-\sqrt{D}}{p-\sqrt{D}+p\sqrt{D}} = - \frac{p^2 + \ldots + p^t + Ap^{t+1}}{(1-A+Ap)p^{t+1}} \\&= -\frac{1}{B}\left( \frac{1}{p^{t-1}}+ \ldots + \frac{1}{p} \right) - \frac{A}{B}, \end{aligned}

where $$B = 1 - A + Ap$$ and $$v_p(A) = v_p(B) = 0$$. Now, we prove that $$\frac{1}{B} = 2 + Cp^t$$ for some C such that $$v_p(C) = 0$$. In this way, it follows that

\begin{aligned} b_3 = t(\alpha _3) = -2\left( \frac{1}{p^{t-1}} + \cdots + \frac{1}{p} \right) = - \frac{p^{t-1} - 1}{2kp^{t-1}}, \end{aligned}

considering that $$4k = p-1$$. To prove that $$\frac{1}{B} = 2 + Cp^t$$, first of all we can observe that

\begin{aligned} B=&1 + \left( \frac{p-1}{2} - p + \frac{p-1}{2}p^2 - \cdots +\frac{p-1}{2} p^{t-1} + \cdots \right) \\&+ \left( -\frac{p-1}{2} p + p^2 - \frac{p-1}{2}p^3 + \cdots - \frac{p-1}{2} p^{t} + \ldots \right) . \end{aligned}

Using that $$1 + \frac{p-1}{2} = - \frac{p-1}{2} + p$$, we obtain

\begin{aligned} B = -\frac{p-1}{2} - \frac{p-1}{2} p - \cdots - \frac{p-1}{2}p^t + \cdots \end{aligned}

Thus, we have that $$\dfrac{1}{B} = 2 + \cdots$$ and we want to prove that $$v_p\left( \frac{1}{B} - 2\right) \ge t+1$$. To prove this, it is sufficient to observe that

\begin{aligned} 1 - 2B = p^{t+1} + \ldots \end{aligned}

We continue to apply Browkin II and we get, after some calculations,

\begin{aligned} \alpha _4 = \frac{p^t(p-1)}{p^t - p - (p-1)\sqrt{D}}. \end{aligned}

Exploiting the previous results, we have

\begin{aligned} \alpha _4 = -\frac{1}{1+Ap}, \end{aligned}

and considering that $$\frac{-1}{1+Ap} = -1 +\ldots$$, we obtain $$b_4 = -1$$. For the next step, we have

\begin{aligned} \alpha _5 = \frac{p-p^t+(p-1)\sqrt{D}}{p-p^{t+1}+(p-1)\sqrt{D}} = 1+ \frac{1}{Ap} = \frac{2}{p} - 1 + \ldots \end{aligned}

from which $$b_5 = t(\alpha _5) = \frac{2}{p}$$. Finally, one can check that

\begin{aligned} \frac{1}{\alpha _5 - b_5} = \alpha _2, \end{aligned}

and the thesis follows.

### Corollary 19

Given p an odd prime, there exist infinitely many $$D \in \mathbb Z$$ such that $$\sqrt{D} \in \mathbb Q_p$$ has Browkin II continued fraction expansion which is periodic of period 4.

### Proof

Since p and $$(1-p)^2$$ are coprime, then there exist infinitely many integers t such that $$p^t \equiv 1 \pmod {(1-p)^2}$$. By Theorem 18 we know that $$\sqrt{\frac{1 - p^t}{(1-p)^2}\cdot p^2}$$ has a p-adic expansion with period 4 by means of Browkin II for all $$t \ge 2$$ and the thesis follows.

## 5 Conclusions

In this paper we mainly analyzed the periodicity of Browkin II that, at the state of the art, is the closest to a standard algorithm for continued fractions over $$\mathbb {Q}_p$$, in terms of its properties regarding finiteness and periodicity (as Browkin observed in [2], it appears to provide more periodic expansions for quadratic irrationals than Browkin I).

In Sect. 3, we found a necessary condition for the pure periodicity, that turns out to be not sufficient in general, in contrast on what Bedocchi proved for Browkin I in [11]. On this purpose, Theorem 10 gives conditions to obtain the pure periodicity of the expansion in most cases. The motivations for the existence of rare exceptions are underlined in Remark 11 and Example 12 and, in some sense, they implicitly characterize the pure periodicity of Browkin II. It would be of great interest to find a full explicit characterization for the p-adic numbers having a pure periodic Browkin II continued fraction. Regarding the preperiod, Bedocchi proved in [11] that the lengths of the preperiods of Browkin I expansions of square roots of integers could only be 2 or 3 and gave explicit conditions on when this happens. On this purpose, we proved that the periodic expansions for square roots of integers obtained by Browkin II can only have preperiod of length 1 or even. In the future, we aim to deepen the study of the preperiods for Browkin II algorithm, trying to give more detailed conditions to distinguish the case of each possible preperiod, in view of Proposition 17.

In Sect. 4, we obtained infinitely many square roots of integers that have a periodic expansion by means of Browkin II with period length 4, solving a problem left open by Browkin in [2] and generalizing what he obtained in the same paper for the period length 2. Moreover, through some experimental results, we believe that is possible to extend this result for all even period lengths. We can summarize these thoughts in the following conjecture:

### Conjecture 20

For all even $$h\in \mathbb {Z}$$, there exist infinitely many $$\sqrt{D}$$, $$D\in \mathbb {Z}$$ not perfect square, such that Browkin II continued fraction of $$\sqrt{D}$$ is periodic with period of length h [19].