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.




' FB 1.05.0 Win64
 
Function nonSquare (n As UInteger) As UInteger
  Return CUInt(n + Int(0.5 + Sqr(n)))
End Function
 
Function isSquare (n As UInteger) As Boolean
  Dim As UInteger r = CUInt(Sqr(n))
  Return n = r * r
End Function
 
Print "The first 22 numbers generated by the sequence are :"
For i As Integer = 1 To 22
  Print nonSquare(i); " ";
Next
 
Print : Print
 
' Test numbers generated for n less than a million to see if they're squares
 
For i As UInteger = 1 To 999999
  If isSquare(nonSquare(i)) Then 
    Print "The number generated by the sequence for n ="; i; " is square!"
    Goto finish
  End If
Next
 
Print "None of the numbers generated by the sequence for n < 1000000 are square"
 
finish:
Print
Print "Press any key to quit"
Sleep