Jack and Jill each have marble collections. The number in Jack's collection in a square number.
Jack says to Jill, "If you give me all your marbles I'll still have a square number." Jill replies, "Or, if you gave me the number in my collection you would still be left left with an even square."
What is the fewest number of marbles Jack could have?
First, I'll just restate what I determined in my previous post. Call the number of marbles Jack has x, and the number of Jill has is y. Since x is a square, let n be the square root of x. Also, x-y and x+y are perfect squares, so (n-a)² = x-y and (n+b)² = x+y for some integers a and b.
With some algebraic manipulation, I came up with two equations:
y = 2na - a² = 2nb + b²
and
n = (a² + b²)/2(a-b)
and of course,
x = n²
Whenever the values for a and b give an integer n, the resulting values of x and y are a solution to the problem. I also showed that a and b must both be even and 0 < b < a. It is not necessary that b < a < n, but whenever a is greater than n, you have a repeated solution (for example, a=4, b=2 and a=6, b=2 give the same result, with n=2 and n=-2 respectively).
All that being said, I wrote the following small javascript to find all valid solutions. I checked all values 0 < b < a < 30, and eliminated repeated values (there were six altogether) by specifying that n>a. The smallest answer is the one that I previously said was the simplest.
For the sake of argument, the smallest 'even' (divisible by two) result is just double the simplest result (Jack and Jill each have four times as many marbles).
Here's the program:
function isInt(x) {
return (x == Math.round(x));
}
for (var b=1; b<30; b++) {
for (var a=b+1; a<30; a++) {
var n = (a*a+b*b)/(2*a-2*b);
var x = n*n;
var y = 2*n*a - a*a; // = 2*n*b + b*b;
if (isInt(n) && n>a) {
document.write("x = " + x + " = " +n + "²<br>");
document.write("y = " + y + "<br>");
document.write("x - y = " + (x-y) + " = " + (n-a) + "²<br>");
document.write("x + y = " + (x+y) + " = " + (n+b) + "²<br>");
document.write("[ a=" + a + "; b=" + b + "; n=" + n + " ]<p>");
}
}
}
And the output:
x = 25 = 5²
y = 24
x - y = 1 = 1²
x + y = 49 = 7²
[ a=4; b=2; n=5 ]
x = 169 = 13²
y = 120
x - y = 49 = 7²
x + y = 289 = 17²
[ a=6; b=4; n=13 ]
x = 100 = 10²
y = 96
x - y = 4 = 2²
x + y = 196 = 14²
[ a=8; b=4; n=10 ]
x = 625 = 25²
y = 336
x - y = 289 = 17²
x + y = 961 = 31²
[ a=8; b=6; n=25 ]
x = 289 = 17²
y = 240
x - y = 49 = 7²
x + y = 529 = 23²
[ a=10; b=6; n=17 ]
x = 225 = 15²
y = 216
x - y = 9 = 3²
x + y = 441 = 21²
[ a=12; b=6; n=15 ]
x = 1681 = 41²
y = 720
x - y = 961 = 31²
x + y = 2401 = 49²
[ a=10; b=8; n=41 ]
x = 676 = 26²
y = 480
x - y = 196 = 14²
x + y = 1156 = 34²
[ a=12; b=8; n=26 ]
x = 400 = 20²
y = 384
x - y = 16 = 4²
x + y = 784 = 28²
[ a=16; b=8; n=20 ]
x = 3721 = 61²
y = 1320
x - y = 2401 = 49²
x + y = 5041 = 71²
[ a=12; b=10; n=61 ]
x = 1369 = 37²
y = 840
x - y = 529 = 23²
x + y = 2209 = 47²
[ a=14; b=10; n=37 ]
x = 625 = 25²
y = 600
x - y = 25 = 5²
x + y = 1225 = 35²
[ a=20; b=10; n=25 ]
x = 7225 = 85²
y = 2184
x - y = 5041 = 71²
x + y = 9409 = 97²
[ a=14; b=12; n=85 ]
x = 2500 = 50²
y = 1344
x - y = 1156 = 34²
x + y = 3844 = 62²
[ a=16; b=12; n=50 ]
x = 1521 = 39²
y = 1080
x - y = 441 = 21²
x + y = 2601 = 51²
[ a=18; b=12; n=39 ]
x = 1156 = 34²
y = 960
x - y = 196 = 14²
x + y = 2116 = 46²
[ a=20; b=12; n=34 ]
x = 900 = 30²
y = 864
x - y = 36 = 6²
x + y = 1764 = 42²
[ a=24; b=12; n=30 ]
x = 841 = 29²
y = 840
x - y = 1 = 1²
x + y = 1681 = 41²
[ a=28; b=12; n=29 ]
x = 12769 = 113²
y = 3360
x - y = 9409 = 97²
x + y = 16129 = 127²
[ a=16; b=14; n=113 ]
x = 4225 = 65²
y = 2016
x - y = 2209 = 47²
x + y = 6241 = 79²
[ a=18; b=14; n=65 ]
x = 1225 = 35²
y = 1176
x - y = 49 = 7²
x + y = 2401 = 49²
[ a=28; b=14; n=35 ]
x = 21025 = 145²
y = 4896
x - y = 16129 = 127²
x + y = 25921 = 161²
[ a=18; b=16; n=145 ]
x = 6724 = 82²
y = 2880
x - y = 3844 = 62²
x + y = 9604 = 98²
[ a=20; b=16; n=82 ]
x = 2704 = 52²
y = 1920
x - y = 784 = 28²
x + y = 4624 = 68²
[ a=24; b=16; n=52 ]
x = 32761 = 181²
y = 6840
x - y = 25921 = 161²
x + y = 39601 = 199²
[ a=20; b=18; n=181 ]
x = 10201 = 101²
y = 3960
x - y = 6241 = 79²
x + y = 14161 = 119²
[ a=22; b=18; n=101 ]
x = 5625 = 75²
y = 3024
x - y = 2601 = 51²
x + y = 8649 = 93²
[ a=24; b=18; n=75 ]
x = 48841 = 221²
y = 9240
x - y = 39601 = 199²
x + y = 58081 = 241²
[ a=22; b=20; n=221 ]
x = 14884 = 122²
y = 5280
x - y = 9604 = 98²
x + y = 20164 = 142²
[ a=24; b=20; n=122 ]
x = 5476 = 74²
y = 3360
x - y = 2116 = 46²
x + y = 8836 = 94²
[ a=28; b=20; n=74 ]
x = 70225 = 265²
y = 12144
x - y = 58081 = 241²
x + y = 82369 = 287²
[ a=24; b=22; n=265 ]
x = 21025 = 145²
y = 6864
x - y = 14161 = 119²
x + y = 27889 = 167²
[ a=26; b=22; n=145 ]
x = 97969 = 313²
y = 15600
x - y = 82369 = 287²
x + y = 113569 = 337²
[ a=26; b=24; n=313 ]
x = 28900 = 170²
y = 8736
x - y = 20164 = 142²
x + y = 37636 = 194²
[ a=28; b=24; n=170 ]
x = 133225 = 365²
y = 19656
x - y = 113569 = 337²
x + y = 152881 = 391²
[ a=28; b=26; n=365 ]
Just for kicks, changing the n>a to n<=a gives the negative values:
x = 25 = 5²
y = 24
x - y = 1 = -1²
x + y = 49 = 7²
[ a=6; b=2; n=5 ]
x = 100 = 10²
y = 96
x - y = 4 = -2²
x + y = 196 = 14²
[ a=12; b=4; n=10 ]
x = 169 = 13²
y = 120
x - y = 49 = -7²
x + y = 289 = 17²
[ a=20; b=4; n=13 ]
x = 225 = 15²
y = 216
x - y = 9 = -3²
x + y = 441 = 21²
[ a=18; b=6; n=15 ]
x = 289 = 17²
y = 240
x - y = 49 = -7²
x + y = 529 = 23²
[ a=24; b=6; n=17 ]
x = 400 = 20²
y = 384
x - y = 16 = -4²
x + y = 784 = 28²
[ a=24; b=8; n=20 ]
Edited on November 3, 2003, 6:57 pm
|
Posted by DJ
on 2003-11-03 18:52:02 |