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.




$ include "seed7_05.s7i";
  include "float.s7i";
  include "math.s7i";
 
const func integer: nonsqr (in integer: n) is
  return n + trunc(0.5 + sqrt(flt(n)));
 
const proc: main is func
  local
    var integer: i is 0;
    var float: j is 0.0;
  begin
    # First 22 values (as a list) has no squares:
    for i range 1 to 22 do
      write(nonsqr(i) <& " ");
    end for;
    writeln;
 
    # The following check shows no squares up to one million:
    for i range 1 to 1000000 do
      j := sqrt(flt(nonsqr(i)));
      if j = floor(j) then
        writeln("Found square for nonsqr(" <& i <& ")");
      end if;
    end for;
  end func;