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.




import "/fmt" for Fmt
 
System.print("The first 22 numbers in the sequence are:")
System.print("  n  term")
for (n in 1...1e6) {
    var s = n + (0.5 + n.sqrt).floor
    var ss = s.sqrt.round
    if (ss * ss == s) {
        Fmt.print("The $r number in the sequence $d = $d x $d is a square.", n, s, ss, ss)
        return
    }
    if (n <= 22) Fmt.print(" $2d   $2d", n, s)
}
System.print("\nNo squares were found in the first 999,999 terms.")