Task

Show that the following remarkable formula gives the sequence of non-square natural numbers:

            n + floor(1/2 + sqrt(n)) 

 Print out the values for    n    in the range   1   to   22
 Show that no squares occur for    n    less than one million


This is sequence   A000037   in the OEIS database.




fcn seq(n){n + (0.5+n.toFloat().sqrt()).floor()}
[1..22].apply(seq).toString(*).println();
 
fcn isSquare(n){n.toFloat().sqrt().modf()[1]==0.0}
isSquare(25)  //-->True
isSquare(26)  //-->False
[2..0d1_000_000].filter(fcn(n){isSquare(seq(n))}).println();