Question:
Find the number of increasing arithmetic progressions of length three, whose terms can range from 1 to 1000. The terms must consist entirely of perfect squares.
Answer: 7
Solved using the script below which resulted in the following arithmetic progressions:
1 25 49
4 100 196
9 225 441
16 400 784
49 169 289
49 289 529
289 625 961
function isInt(value) {
return !isNaN(parseInt(value,10)) && (parseFloat(value,10) == parseInt(value,10));
}
function isPerfectSquare(value){
if(isInt(Math.sqrt(value))){
return true;
} else {
return false;
}
}
console.log("**************************************");
var max = 1000;
for(var a=1; a<=max; a++){
for(var b=1; b<=max; b++){
for(var c=1; c<=max; c++){
if(b-a==c-b && a<b && b<c && isPerfectSquare(a) && isPerfectSquare(b) && isPerfectSquare(c)){
console.log(""+a+" "+b+" "+c+"");
}
}
}
}
Please take down this post
ReplyDelete-Calvin Lin
Brilliant Mathematics Challenge Master