Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|cite|improve this question
Your title asks a different question than the body of your question; you might want to fix that. – Niel de Beaudrap Sep 14 '12 at 21:27
Sigh. In the title you say $x^2 - y^2,$ which has integer solutions. With a plus sign there are no integer solutions. – Will Jagy Sep 14 '12 at 21:27
Done, it's x^2-y^2, sorry for that ;) – Devos50 Sep 14 '12 at 21:28
$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.$ – Will Jagy Sep 14 '12 at 21:30
up vote 13 down vote accepted

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$.

share|cite|improve this answer

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.

share|cite|improve this answer

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$.

share|cite|improve this answer
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 ;) – Devos50 Sep 14 '12 at 21:43
@Devos50 Let $y=x+n$. – Alex Becker Sep 14 '12 at 21:45

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}$

share|cite|improve this answer
Oh, the colors! image – The Chaz 2.0 Sep 14 '12 at 23:56

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.

share|cite|improve this answer
You should use MathJax to format your answer. – Michael Albanese Oct 19 '15 at 1:59
I do not have MathJax. – user281688 Nov 9 '15 at 22:57
Math.SE has MathJax, it is not something that you need. – Michael Albanese Nov 10 '15 at 17:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.