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.




link numbers
 
procedure main()
 
every n := 1 to 22 do
  write("nsq(",n,") := ",nsq(n))
 
every x := sqrt(nsq(n := 1 to 1000000)) do
  if x  = floor(x)^2 then write("nsq(",n,") = ",x," is a square.")
write("finished.")
end
 
procedure nsq(n)   # return non-squares
return n + floor(0.5 + sqrt(n))
end