Quotes help make search much faster. Example: "Practice Makes Perfect"

Sunday, January 6, 2013

Math Problems: Arithmetic Progression with Perfect Square Terms



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+"");
}
}
}
}

1 comment:

  1. Please take down this post

    -Calvin Lin
    Brilliant Mathematics Challenge Master

    ReplyDelete


This is an example of scrolling text using Javascript.

Popular Posts