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.




# Display first 22 values
print "The first 22 numbers generated by the sequence are : "
for i = 1 to 22
    print nonSquare(i); " ";
next i
print
 
# Check for squares up to one million
found = false
for i = 1 to 1e6
    j = sqrt(nonSquare(i))
    if j = int(j) then
        found = true
        print i, " square numbers found"
        exit for
    end if
next i
if not found then print "No squares found"
end
 
function nonSquare (n)
    return n + int(0.5 + sqrt(n))
end function