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.




  $ "bigrat.qky" loadfile
 
  [ dup n->v 2 vsqrt
    drop 1 2 v+ / + ] is nonsquare ( n --> n )
 
  [ sqrt nip 0 = ]    is squarenum ( n --> b ) 
 
  say "Non-squares: "
  22 times [ i^ 1+ nonsquare echo sp ]
  cr cr
  0 
  999999 times 
    [ i^ 1+ nonsquare
      squarenum if 1+ ] 
  echo say " square numbers found"