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.




with javascript_semantics

sequence s = repeat(0,22)
for n=1 to length(s) do
    s[n] = n + floor(1/2 + sqrt(n))
end for
printf(1,"%V\n",{s})
integer nxt = 2, snxt = nxt*nxt, k
for n=1 to 1000000 do
    k = n + floor(1/2 + sqrt(n))
    if k>snxt then
--      printf(1,"%d didn't occur\n",snxt)
        nxt += 1
        snxt = nxt*nxt
    end if
    if k=snxt then
        puts(1,"error!!\n")
    end if
end for
puts(1,"none found ")
?{nxt,snxt}
