# Solutions to a quadratic diophantine equation $x^2 + xy + y^2 = 3r^2$.

Let $k,i,r \in\Bbb Z$, $r$ constant. How to compute the number of solutions to $3(k^2+ki+i^2)=r^2$, perhaps by generating all of them?

• The accepted answer is incorrect for the stated problem with "r constant". For that problem there are only a finite number of solutions. Finding the solutions, similar to the Pythagorean case $a(x^2 + y^2) = r^2$, is a problem of integer factorization in the ring of integers of a quadratic (and cyclotomic) field. – zyx Jun 8 '16 at 18:05
• I've edited the title with notation that ever so slightly conflicts with the one in the question, but better represents the actual material in the question and any solutions that might appear. Just "for your information" in case you prefer to reverse the edit. @qqq – zyx Jun 8 '16 at 18:20

There are infinitely many solutions to this Diophantine equation.

I change your variables. We have the Diophantine equation$$3(a^2+ab+b^2)=c^2$$Let's assume $c$ is not constant and find all possible solutions! $c=0$ gives $a=b=0$. W.L.O.G. suppose $c>0$. It's easy to see that $c=3d$ for some positive integer $d$. Equation becomes$$a^2+ab+b^2=3d^2$$For $a=b$ we get $a=b=\pm d$. W.L.O.G. suppose that $a>b$. Notice that$$a^2+ab+b^2 \equiv 0 \pmod 3$$It follows that $a^3 \equiv b^3 \pmod 3$ and $a \equiv b \pmod 3$. Let $a-b=3e$ for some positive integer $e$. Equation turns into$$b^2+3be+3e^2=d^2$$In order to get integer values for $b$ discriminant of this quadratic must be a perfect square, that is$$\Delta_{b}=-3e^2+4d^2=f^2$$For some integer $f$.

$f=0$ gives $\sqrt{3}=2\frac{d}{e}$, which is impossible. W.L.O.G. suppose that $f>0$. Therefore, we need to solve$$f^2+3e^2=4d^2$$In positive integers. Now this is of the form of extended Pythagorean equation $Ax^2+By^2=Cz^2$, which is widely studied. Even there are some questions here and here, which exactly discuss your particular case!

Once you find parametric forms of $f$, $e$ and $d$, you can substitute backwards and find parametric form of your original variables $a$, $b$ and $c$.

The solutions can be parametrized very nicely, three binary quadratic forms. The approach of Fricke and Klein (1897) guarantees a solution with a finite number of such parametrizations, here there is just one needed. I had it report just those with $xy > 0,$ each of these leads to two others with $xy < 0,$ those being $(-x,x+y)$ and $(x+y,-y).$ You can just negate both $x,y$ to get all positive. Negating all three leads, in general, to six solutions for each $r$ prime, $r \equiv 1 \pmod 6.$ More if $r$ is the product of such primes, compare $91 = 7 \cdot 13.$ $$r = u^2 - uv + v^2, \; \; x = u^2 + 2uv - 2 v^2, \; \; y = -2u^2 + 2uv+ v^2$$

Let's see, My program to find the coefficients for such parametrizations is in C++,

jagy@phobeusjunior:~$./homothety_indef 1 1 -3 0 0 1 0 9 0 0 -9 0 2 .... -2 -2 1 transposed -2 1 -1 1 -2 -2 transposed -2 -2 -1 -1 -1 -1 transposed 1 -2 -1 ...... apparently I chose the next one 1 2 -2 transposed 1 -2 1 -2 2 1 transposed 2 2 -1 1 -1 1 transposed -2 1 1   r x y u v r 1 1 1 1 1 1 = 1 7 -2 -11 2 -1 7 = 7 13 22 1 4 3 13 = 13 19 -11 -26 3 -2 19 = 19 31 46 13 6 5 31 = 31 37 -26 -47 4 -3 37 = 37 43 61 22 7 6 43 = 43 49 -23 -71 5 -3 49 = 7^2 61 -47 -74 5 -4 61 = 61 67 109 13 9 7 67 = 67 73 97 46 9 8 73 = 73 79 -11 -131 7 -3 79 = 79 91 118 61 10 9 91 = 7 * 13 91 -74 -107 6 -5 91 = 7 * 13 97 -2 -167 8 -3 97 = 97 103 157 37 11 9 103 = 103 109 -71 -143 7 -5 109 = 109 127 -107 -146 7 -6 127 = 127 133 166 97 12 11 133 = 7 * 19 133 -23 -218 9 -4 133 = 7 * 19 139 229 22 13 10 139 = 139 151 -59 -227 9 -5 151 = 151 157 193 118 13 12 157 = 157 163 262 37 14 11 163 = 163 169 -146 -191 8 -7 169 = 13^2 181 313 1 15 11 181 = 181 193 -143 -239 9 -7 193 = 193 199 277 109 15 13 199 = 199 211 253 166 15 14 211 = 211 217 -191 -242 9 -8 217 = 7 * 31 217 334 73 16 13 217 = 7 * 31 223 -83 -338 11 -6 223 = 223 229 -26 -383 12 -5 229 = 229 241 286 193 16 15 241 = 241 247 -131 -347 11 -7 247 = 13 * 19 247 373 94 17 14 247 = 13 * 19 259 -11 -443 13 -5 259 = 7 * 37 259 349 157 17 15 259 = 7 * 37 271 -242 -299 10 -9 271 = 271 277 -122 -407 12 -7 277 = 277 283 -59 -458 13 -6 283 = 283 301 -239 -359 11 -9 301 = 7 * 43 301 481 73 19 15 301 = 7 * 43 307 358 253 18 17 307 = 307 313 457 142 19 16 313 = 313 331 -299 -362 11 -10 331 = 331 337 -167 -482 13 -8 337 = 337 343 397 286 19 18 343 = 7^3 349 502 169 20 17 349 = 349 361 601 46 21 16 361 = 19^2 367 -227 -491 13 -9 367 = 367 373 577 121 21 17 373 = 373 379 -83 -611 15 -7 379 = 379 397 -362 -431 12 -11 397 = 397 403 -218 -563 14 -9 403 = 13 * 31 403 517 277 21 19 403 = 13 * 31 409 -143 -626 15 -8 409 = 409 421 481 358 21 20 421 = 421 427 598 229 22 19 427 = 7 * 61 427 733 13 23 17 427 = 7 * 61 433 -359 -503 13 -11 433 = 433 439 709 94 23 18 439 = 439 457 -47 -767 17 -7 457 = 457 463 526 397 22 21 463 = 463 469 -431 -506 13 -12 469 = 7 * 67 469 649 262 23 20 469 = 7 * 67 481 -194 -719 16 -9 481 = 13 * 37 481 766 121 24 19 481 = 13 * 37 487 613 349 23 21 487 = 487 499 -26 -851 18 -7 499 = 499 511 -347 -659 15 -11 511 = 7 * 73 511 853 61 25 19 511 = 7 * 73 523 -179 -803 17 -9 523 = 523 541 793 241 25 21 541 = 541 547 -506 -587 14 -13 547 = 547 553 -338 -743 16 -11 553 = 7 * 79 553 622 481 24 23 553 = 7 * 79 559 -251 -818 17 -10 559 = 13 * 43 559 757 334 25 22 559 = 13 * 43 571 886 181 26 21 571 = 571 577 -71 -962 19 -8 577 = 577 589 1009 22 27 20 589 = 19 * 31 589 -503 -671 15 -13 589 = 19 * 31 601 673 526 25 24 601 = 601 607 814 373 26 23 607 = 607 613 -143 -983 19 -9 613 = 613 619 949 214 27 22 619 = 619 631 -587 -674 15 -14 631 = 631 637 -407 -842 17 -12 637 = 7^2 * 13 637 913 313 27 23 637 = 7^2 * 13 643 -314 -923 18 -11 643 = 643 661 -122 -1079 20 -9 661 = 661 673 -23 -1154 21 -8 673 = 673 679 -491 -851 17 -13 679 = 7 * 97 679 829 517 27 25 679 = 7 * 97 691 -299 -1019 19 -11 691 = 691 703 1117 181 29 23 703 = 19 * 37 703 781 622 27 26 703 = 19 * 37 709 934 457 28 25 709 = 709 721 1081 286 29 24 721 = 7 * 103 721 -674 -767 16 -15 721 = 7 * 103 727 -482 -947 18 -13 727 = 727 733 -383 -1034 19 -12 733 = 733 739 1222 109 30 23 739 = 739 751 -179 -1202 21 -10 751 = 751 757 838 673 28 27 757 = 757 763 -74 -1283 22 -9 763 = 7 * 109 763 997 502 29 26 763 = 7 * 109 769 -671 -863 17 -15 769 = 769 787 949 613 29 27 787 = 787 793 1297 142 31 24 793 = 13 * 61 793 -263 -1223 21 -11 793 = 13 * 61 811 1261 253 31 25 811 = 811 817 -47 -1391 23 -9 817 = 19 * 43 817 -767 -866 17 -16 817 = 19 * 43 823 -563 -1058 19 -14 823 = 823 829 -458 -1151 20 -13 829 = 829 853 1177 481 31 27 853 = 853 859 -131 -1418 23 -10 859 = 859 871 -659 -1067 19 -15 871 = 13 * 67 871 958 781 30 29 871 = 13 * 67 877 1129 598 31 28 877 = 877 883 -443 -1259 21 -13 883 = 883 889 1294 409 32 27 889 = 7 * 127 889 1489 97 33 25 889 = 7 * 127 907 1453 214 33 26 907 = 907 919 -866 -971 18 -17 919 = 919 931 1021 838 31 30 931 = 7^2 * 19 931 1606 13 34 25 931 = 7^2 * 19 937 1198 649 32 29 937 = 937 949 1369 454 33 28 949 = 13 * 73 949 -311 -1466 23 -12 949 = 13 * 73 961 -194 -1559 24 -11 961 = 31^2 967 1534 253 34 27 967 = 967 r x y u v r  ==================================== A few questions/answers that display this method$x^2+y^2+z^2=5(xy+yz+zx)$-- Is this all solutions? Solving a Diophantine equation of the form$x^2 = ay^2 + byz + cz^2$with the constants$a, b, c$given and$x,y,z$positive integers Help solving$ax^2+by^2+cz^2+dxy+exz+fzy=0$where$(x_0,y_0,z_0)$is a known integral solution The next one shows the English excerpt from Plesken that describes the central fact from F+K(1897): Describe the rational points on$3x^2 + y^2 = 4$Question about non-degenerate polynomials, and a proof • Can you share your source code or provide a reference for the F&K method? – qqq Jun 10 '16 at 16:13 • @qqq I put some links at the end. – Will Jagy Jun 10 '16 at 17:26 Generally, you can use the General formula. Solving a Diophantine equation of the form$x^2 = ay^2 + byz + cz^2$with the constants$a, b, c$given and$x,y,z$positive integers $$ax^2+bxy+cy^2=jz^2$$ For our case. $$x^2+xy+y^2=3z^2$$ $$\sqrt{b^2+4a(j-c)}=3$$ $$\sqrt{j(a+b+c)}=3$$ There is a solution. The formula remains only to substitute. $$c\,{{x}^{2}}+dyx+g\,{{y}^{2}}=ab$$ $$\downarrow$$ $$g\,{{\left( psc+hkc+dks\right) }^{2}}+c\,{{\left( hpc-gks\right) }^{2}}+d\,\left( hpc-gks\right) \,\left( psc+hkc+dks\right) =$$ $$=c\,\left( {{h}^{2}}c+g\,{{s}^{2}}+dhs\right) \,\left( {{p}^{2}}c+dkp+g\,{{k}^{2}}\right)$$ $$\downarrow$$ $$c\,{{x}^{2}}+dyx+g\,{{y}^{2}}=a\,{{z}^{2}}$$ $$\downarrow$$ $$c\,{{\left( -cgp\,{{s}^{2}}-dgk\,{{s}^{2}}-2cghks+{{c}^{2}}\,{{h}^{2}}p\right) }^{2}}+$$ $$+g\,{{\left( cdp\,{{s}^{2}}-cgk\,{{s}^{2}}+{{d}^{2}}k\,{{s}^{2}}+2{{c}^{2}}hps+2cdhks+{{c}^{2}}\,{{h}^{2}}k\right) }^{2}}+$$ $$+d\,\left( cdp\,{{s}^{2}}-cgk\,{{s}^{2}}+{{d}^{2}}k\,{{s}^{2}}+2{{c}^{2}}hps+2cdhks+{{c}^{2}}\,{{h}^{2}}k\right)\cdot$$ $$\cdot\left( -cgp\,{{s}^{2}}-dgk\,{{s}^{2}}-2cghks+{{c}^{2}}\,{{h}^{2}}p\right)=$$ $$={{c}^{2}}\,\left( c\,{{p}^{2}}+dkp+g\,{{k}^{2}}\right) \,{{\left( g\,{{s}^{2}}+dhs+c\,{{h}^{2}}\right) }^{2}}$$ $$------------------------------$$ For$\;\;{{x}^{2}}+yx+{{y}^{2}}=3{{r}^{2}},\;\;c=1,\;d=1,\;g=1,\;{{p}^{2}}+kp+{{k}^{2}}=3\$

Two solutions:

$$r={{s}^{2}}+hs+{{h}^{2}},\;\;x=-{{s}^{2}}+2hs+2{{h}^{2}},\;\;y=2{{s}^{2}}+2hs-{{h}^{2}}$$

$$r={{s}^{2}}+hs+{{h}^{2}},\;\;x={{s}^{2}}-2hs-2{{h}^{2}},\;\;y={{s}^{2}}+4hs+{{h}^{2}}$$