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.




open System
 
let SequenceOfNonSquares =
    let nonsqr n = n+(int(0.5+Math.Sqrt(float (n))))
    let isqrt n = int(Math.Sqrt(float(n)))
    let IsSquare n = n = (isqrt n)*(isqrt n)
    {1 .. 999999}
    |> Seq.map(fun f -> (f, nonsqr f))
    |> Seq.filter(fun f -> IsSquare(snd f))
;;