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.




 
class Main
{
  static Float fn (Int n)
  {
    n + (0.5f + (n * 1.0f).sqrt).floor
  }
 
  static Bool isSquare (Float n)
  {
    n.sqrt.floor == n.sqrt
  }
 
  public static Void main ()
  {
    (1..22).each |n|
    {
      echo ("$n is ${fn(n)}")
    }
    echo ((1..1000000).toList.any |n| { isSquare (fn(n)) } )
  }
}
 