Thank you Andrei from Tudor Vianu National
College, Bucharest, Romania for this solution.
First I looked at the values of $A$ and $B$ for the first values of
$n$ in the expansion of $(1 + \sqrt 2)^n = A + B\sqrt 2$. The
results I obtained are written in the following table:
$n$ 
$A$ 
$B$ 
1 
1 
1 
2 
3 
2 
3 
7 
5 
4 
17 
12 
5 
41 
29 
In the cases studied, I observe that $A$ is odd for all $n$, and
that $B$ is odd for $n$ odd and even for $n$ even. Now, I shall
generalise this result by induction for any $n$:
First I assume that $A(n)$ and $B(n)$ are odd and I prove that
$A(n+1)$ is odd and $B(n+1)$ is even. This corresponds to $n$ odd.
I shall consider $A(n) = 2p+1$ and $B(n) = 2q+1$.
So, $(1 + \sqrt 2)^n = (2p+1) + (2q+1)\sqrt 2$. $$(1 + \sqrt
2)^{n+1} = (1 + \sqrt 2)^n (1+\sqrt 2) = ((2p+1) + (2q+1)\sqrt
2)(1+ \sqrt 2) = (2p+1 + 2(2q+1)) + \sqrt 2 (2q+1+2p+1).$$ So,
$A(n+1) = 2(p+2q+1) + 1$ and $B(n+1) = 2(p+q+1).$ These values that
I have obtained for A(n+1) and B(n+1) confirm my prediction.
In a similar manner I assume $A(n)$ odd and $B(n)$ even:
$A(n) = 2p+1$, $B(n) = 2q$. I obtain:
$A(n+1) = 2(p+2q) + 1$ and $B(n+1) = 2(p+q) + 1$.
Now, my proof by induction is complete.
The results are summarized in the following table:

$A$ even 
$A$ odd 
$B$ even 
 
$n$ even 
$B$ odd 
 
$n$ odd 
Working in a similar manner for $(a + \sqrt p)^n$, I summarize my
results in the following table:

$n$ 
$A$ 
$B$ 
$a$ odd, $p$ odd 
all $n$ 
even
exception $n=1, A=1$

even
exception $n=1,
B=1$

$a$ even, $p$ even 
all $n$ 
even 
even
exception $n=1,
B=1$

$a$ odd, $p$ even 
odd
even

odd
odd

odd
even

$a$ even, $p$ odd 
odd
even

even
odd

odd
even
