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.




declare
  fun {NonSqr N}
     N + {Float.toInt {Floor 0.5 + {Sqrt {Int.toFloat N}}}}
  end
 
  fun {SqrtInt N}
     {Float.toInt {Sqrt {Int.toFloat N}}}
  end
 
  fun {IsSquare N}
     {Pow {SqrtInt N} 2} == N
  end
 
  Ns = {Map {List.number 1 999999 1} NonSqr}
in
  {Show {List.take Ns 22}}
  {Show {Some Ns IsSquare}}