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.




function nonSquare (n)
    return n + math.floor(1/2 + math.sqrt(n))
end
 
for n = 1, 22 do
    io.write(nonSquare(n) .. " ")
end
print()
local sr
for n = 1, 10^6 do
    sr = math.sqrt(nonSquare(n))
    if sr == math.floor(sr) then
        print("Result for n = " .. n .. " is square!")
        os.exit()
    end
end
print("No squares found")