Non-squarefree version of Pell's equation? Suppose I wanted to solve (for x and y) an equation of the form $x^2-dp^2y^2=1$ where d is squarefree and p is a prime.  Of course I could simply generate the solutions to the Pell equation $x^2-dy^2=1$ and check if the value of y was divisible by $p^2,$ but that would be slow.  Any better ideas?
It would be useful to be able to distinguish cases where the equation is solvable from cases where it is unsolvable, even without finding an explicit solution.
 A: A different and important way to view this equation is still as a norm equation, only in a non-maximal order of the quadratic field - namely, we are looking at the ring $\mathbb{Z}[p\sqrt{d}]$.
Since we are still in the realm of algebra, we can prove results algebraically. For example:
Proposition. Let $p$ be a prime that doesn't divide $d$, and $e=x+y\sqrt{d}$ be a unit with integer $x,y$. Then $e^{p-(d/p)} \in \mathbb{Z}[p\sqrt{d}]$, where $(d/p)$ is the Legendre symbol.
Proof. If the Legendre symbol is $-1$, this means that $(p)$ doesn't split in $O$ (which will denote the maximal order from here on), so that $O/(p)$ is isomorphic to the finite field of size $p^2$. Now every number in $\mathbb{F}_{p^2}$ has order dividing $p^2-1$, so $e^{p+1} \pmod{p}$ has order diving $p-1$. But the numbers of order diving $p-1$ are exactly those in the subfield $\mathbb{F}_p$, and that means that $e^{p+1} = z+pw\sqrt{d}$, proving the claim in this case.
If $(p)$ splits into $\pi_1 \pi_2$, then $O/(p)$ is isomorphic to $O/\pi_1 \pi_2$ which is in turn, by chinese remainder theorem, isomorphic to $\mathbb{F}_p \oplus \mathbb{F}_p$. By inspection we see that the galois action permutes the two coordinates. So, since under the isomorphism $e^{p-1}\pmod{\pi_1}=e^{p-1}\pmod{\pi_2}=1$, we see that $e^{p-1}\pmod{p}$ is invariant. Hence it is of the form $z+pw\sqrt{d}$, proving the claim in this case as well. $\Box$
The above proposition shows how to get solutions to the non-squarefree Pell equation from solutions of the squarefree one - simply power appropriately.
A: For what it is worth, my lecture notes on the Pell Equation are in the context of $d$ any positive, nonsquare integer.  Also see problem 9.2 here where I ask the students to exploit the fact that $d$ does not need to be squarefree to show that one can find solutions $(x,y)$ to the Pell equation satisfying an additional congruence $y \equiv 0 \pmod M$ for any $M \in \mathbb{Z}^+$.
From the perspective of algebraic number theory, this comes down to a version of the Dirichlet Unit Theorem for nonmaximal orders in a number field $K$.  Recall that a $\mathbb{Z}$-order $R$ in $K$ is a subring of $\mathbb{Z}_K$ such that the additive group $(R,+)$ is finitely generated as a $\mathbb{Z}$-module.  The last condition is equivalent to the finiteness of the index $[\mathbb{Z}_K:R]$.  The usual statement of the Dirichlet Unit Theorem is that the unit group $\mathbb{Z}_K^{\times}$ is a finitely generated abelian group with rank equal to $r_1 + r_2 - 1$, where if $K \cong \mathbb{Q}[t]/(P(t))$, the polynomial $P$ has $r_1$ real roots and $r_2$ pairs of complex conjugate non-real roots.
But if I am not mistaken (and please let me know if I am!), the standard proof of the Dirichlet Unit Theorem works to show that exactly the same is true for the unit group $R^{\times}$ of any nonmaximal order.  (Certainly $R^{\times}$ is finitely generated, being a subgroup of the finitely generated abelian group $\mathbb{Z}_K^{\times}$; the claim is that its rank is no less than that of $\mathbb{Z}_K^{\times}$.)
Using the structure theory of finitely generated abelian groups, one easily deduces the following relative version of the Dirichlet Unit Theorem: for any order $R$ in $\mathbb{Z}_K^{\times}$, the quotient group $\mathbb{Z}_K^{\times}/R^{\times}$ is finite.
