5 added 37 characters in body edited Oct 26 '15 at 1:40 J. M. will be back soon♦ 101k1010 gold badges319319 silver badges478478 bronze badges You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13, 10, 365} {133, 108, 35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13, 10, 365} {133, 108, 35645} {1321, 1078, 3492725} {13081, 10680, 342251285} {129493, 105730, 33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from    $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, with all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind that you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance, but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. See also http://oeis.org/A007667 You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from  $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. See also http://oeis.org/A007667 You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13, 10, 365} {133, 108, 35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13, 10, 365} {133, 108, 35645} {1321, 1078, 3492725} {13081, 10680, 342251285} {129493, 105730, 33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from  $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, with all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind that you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance, but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. See also http://oeis.org/A007667 4 added 43 characters in body edited Sep 30 '14 at 9:28 Kellen Myers 2,3281010 silver badges1717 bronze badges You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. See also http://oeis.org/A007667 You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. See also http://oeis.org/A007667 3 remarks about FindInstance edited Sep 30 '14 at 9:09 Kellen Myers 2,3281010 silver badges1717 bronze badges You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can just step through $$i$$ and $$j$$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $$i$$. If it's too small on the right, increment $$j$$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j = 1; While[f[i] <= max && g[i] <= max, If[f[i] == g[j], Print[{i, j, f[i]}]; i++;]; If[f[i] < g[j], i++]; If[f[i] > g[j], j++]; ]; (*Output: {13,10,365} {133,108,35645} *) This executes almost instantaneously. So $$133^2+134^2 = 108^2 + 109^2 + 110^2 = 35645$$. You can increase max to find more, like these: {13,10,365} {133,108,35645} {1321,1078,3492725} {13081,10680,342251285} {129493,105730,33537133085} That's up to $$10^{12}$$, which takes about 10 seconds. Further discussion Any useful algorithm here will focus on the $$i$$ and $$j$$, rather than the $$n$$, from $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2=n$$ If you are searching in a straightforward way, all things equal, checking all possible $$i$$ and $$j$$ (keeping in mind you iterate them together) takes about $$\sqrt{n}$$ time (whereas checking all possible $$n$$ takes, well, $$n$$ time). You can try something using FindInstance but even the following: Timing[FindInstance[i^2 + (i + 1)^2 == j^2 + (j + 1)^2 + (j + 2)^2 && i > 0 && j > 0, {i, j}, Integers]] will still take about ten times as long as the code above. 2 discussion of run time edited Sep 30 '14 at 9:02 Kellen Myers 2,3281010 silver badges1717 bronze badges 1 answered Sep 30 '14 at 8:57 Kellen Myers 2,3281010 silver badges1717 bronze badges