I'm currently trying to solve a programming question that requires me to calculate all the integer solutions of the following equation:

$x^2-y^2 = 33$

I've been looking for a solution on the internet already but I couldn't find anything for this kind of equation. Is there any way to calculate and list the integer solutions to this equation?

Thanks in advance!

  • 2
    $\begingroup$ Your title asks a different question than the body of your question; you might want to fix that. $\endgroup$ Sep 14, 2012 at 21:27
  • 1
    $\begingroup$ Sigh. In the title you say $x^2 - y^2,$ which has integer solutions. With a plus sign there are no integer solutions. $\endgroup$
    – Will Jagy
    Sep 14, 2012 at 21:27
  • $\begingroup$ Done, it's x^2-y^2, sorry for that ;) $\endgroup$
    – Devos50
    Sep 14, 2012 at 21:28
  • 10
    $\begingroup$ $x^2 - y^2 = (x-y)(x+y).$ So both factors are chosen from $\pm 1, \pm 3, \pm 11, \pm 33.$ Then you solve for $x,y.$ $\endgroup$
    – Will Jagy
    Sep 14, 2012 at 21:30

6 Answers 6


Suppose that $x=y+n$; then $x^2-y^2=y^2+2ny+n^2-y^2=2ny+n^2=n(2y+n)$. Thus, $n$ and $2y+n$ must be complementary factors of $33$: $1$ and $33$, or $3$ and $11$. The first pair gives you $2y+1=33$, so $y=16$ and $x=y+1=17$. The second gives you $2y+3=11$, so $y=4$ and $x=y+3=7$. As a check, $17^2-16^2=289-256=33=49-16=7^2-4^2$.

If you want negative integer solutions as well, you have also the pairs $-1$ and $-33$, and $-3$ and $-11$.


We have $x^2-y^2=33$ iff $(x-y)(x+y)=33$. So to solve our equation we find all ordered pairs $(u,v)$ such that $uv=33$. Then we set $x-y=u$ and $x+y=v$, and solve.

We get $x=\dfrac{v+u}{2}$ and $y=\dfrac{v-u}{2}$. Since $u$ and $v$ will be both odd, $u+v$ and $v-u$ will be even, so $x$ and $y$ will be integers.

The possibilities for $u$ are $-33,-11,-3,-1,1,3,11,33$. The corresponding possibilities for $v$ are $-1,-3,-11,-33,33,11,3,1$. There are $8$ solutions, but only two "really different" ones.

For example, let $u=3$ and $v=11$. Then $x=\dfrac{11+3}{2}=7$ and $y=\dfrac{11-3}{2}=4$.

Generalization: If $n$ is of the form $4k+2$, then $n$ is not the difference of two squares. If $n$ is odd, the representations of $n$ as a difference of two squares are found exactly like the $n=33$ case discussed above. If $n$ is of the form $4k$, we do much the same thing, but find all pairs $(u,v)$ such that $uv=n$ and $u$ and $v$ are even.


Hint $\ $ Like sums of squares, there is also a composition law for differences of squares, so

$\rm\quad \begin{eqnarray} 3\, &=&\, \color{#0A0}2^2-\color{#C00}1^2\\ 11\, &=&\, \color{blue}6^2-5^2\end{eqnarray}$ $\,\ \Rightarrow\,\ $ $\begin{eqnarray} 3\cdot 11\, &=&\, (\color{#0A0}2\cdot\color{blue}6+\color{#C00}1\cdot 5)^2-(\color{#0A0}2\cdot 5+\color{#C00}1\cdot\color{blue}6)^2\, =\, 17^2 - 16^2\\ &=&\, (\color{#0A0}2\cdot\color{blue}6-\color{#C00}1\cdot 5)^2-(\color{#0A0}2\cdot 5-\color{#C00}1\cdot\color{blue}6)^2\, =\, \ 7^2\ -\ 4^2 \end{eqnarray}$

  • 2
    $\begingroup$ Oh, the colors! image $\endgroup$ Sep 14, 2012 at 23:56

Note that this is equivalent to solving $(x+n)^2-x^2=33$, and that $(x+n)^2-x^2=(2x+n)n$. Since $33=3\cdot 11$, we see that the solutions are $n=3,x=4$ and $n=11,x=-4$ with $n>0$ and both of thee times $-1$.

  • $\begingroup$ Thank you for your answer. Could you please explain why this is equal to solving (x+n)^2 - x^2? I don't get that part ;) $\endgroup$
    – Devos50
    Sep 14, 2012 at 21:43
  • $\begingroup$ @Devos50 Let $y=x+n$. $\endgroup$ Sep 14, 2012 at 21:45
  • $\begingroup$ Don't forget that $33$ can also be factored as $33\cdot1$. That gives the solution $(17)^2-(16)^2=33$. $\endgroup$ Jan 4, 2021 at 2:31

We can find the $m,n$ values for side A of a Pythagorean triple by solving for $n$ and testing a range of $m$-values to see which, if any, yield integers.

$$A=m^2-n^2\implies n=\sqrt{m^2-A}\qquad\text{where}\qquad \lfloor\sqrt{A+1}\rfloor \le m \le \frac{A+1}{2}$$

The lower limit ensures $n\in\mathbb{N}$ and the upper limit ensures $m> n$. Here is an example

$$A=33\implies \lfloor\sqrt{33+1}\rfloor=5\le m \le \frac{33+1}{2} =17\quad\text{ and we find} \quad m\in\{7,17\}\implies k \in\{4,16\} $$ $$f(7,4)=(33,56,65)\qquad \qquad \qquad f(17,16)=(33,544,545)$$

What this all boils down to is that

$$7^2-4^2=33\qquad\land\qquad 17^2-16^2=33$$


This is all fine, but you all take the initial knowledge of the prime composition of 33 as 11*3, but imagine you did not know that. You would not know it without a lot/ some trial and error , if I instead of 33 took 1771 instead and stated x^2-y^2=1771, then only the few, would know the prime factors of 1771

There are no known ways of solving this problem other than trial and error. Likewise with 33, if you had no knowledge that 11*3= 33

You will have to run through this calculation: sqrt(1771)=42.08 and mod(1171,4)=3 Mod 3 means X^2 is even and y^2 is odd. Had the result been 1, it was opposite.

You can rewrite the equation to y^2= x^2-1771, so both y and x must be integers, x will have an even root and y will have an odd root. Nearest even integer after 42.08 is 44, so that is where I start. (x^2 has to be bigger than 42.08)

We start our trial and error: 44^2-1771= y^2 46^2-1771= y^2 48^2-1771= y^2 If you calculate the first 3, they will generate a y^2, which is not a perfect square, that is, y will not be integer.

But 50^2= 2500-1771= 729 and that gives the roots sqrt(2500)= 50 and sqrt(729)=27, so one solution is (50+27)=77 and the other is (50-27)=23 and 77*23= 1771 It follows the format (x+y)(x-y)= X^2-Y^2 and (50+27)(50-27)= 1771

If we could find a way of getting directly to either 2500 or 729, we would at the same time get a lead to solve some of the Millennium math. problems. I am trying, but have not succeeded.

When you go deeper into this, you might find some short cuts, which can reduce the number of trial and error, but currently there are no ways to reduce it down to just one single cycle. If you find it, let me know.

In this case there are other solutions as well, because the prime composition of 1771 is 7*11*23 and we just solved for (7*11)*23 The product is not changing for other combinations, but the sum of (x+y) and the difference (x-y) is changing, which leads to different perfect squares, but with the same feature, that their difference is 1771.

If you only find ONE solution, your difference is a prime number. A prime number is always the difference of 2 consecutive squares and have no other solutions, than this combination, whereas composite numbers will at least have 2 solutions, the prime composition of 2 consecutive squares and at least one more.

It is amazing and surprising, that there is no way but brute force, to factor an odd number.... however as long as that goes on, we have our financial transactions fairly safe, they rely on the excessive time, it takes to factor a product of 2 large prime numbers.

  • $\begingroup$ You should use MathJax to format your answer. $\endgroup$ Oct 19, 2015 at 1:59
  • $\begingroup$ I do not have MathJax. $\endgroup$
    – user281688
    Nov 9, 2015 at 22:57
  • $\begingroup$ Math.SE has MathJax, it is not something that you need. $\endgroup$ Nov 10, 2015 at 17:05
  • $\begingroup$ you can in fact find the squares without factoring 33=7^2-4^2 or the ones for 1771. It does however involve some trial and error but a lot simpler to carry out. $\endgroup$
    – user25406
    Apr 11, 2019 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .