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.




 
program Sequence_of_non_squares;
 
uses
  System.SysUtils, System.Math;
 
function nonsqr(i: Integer): Integer;
begin
  Result := Trunc(i + Floor(0.5 + Sqrt(i)));
end;
 
var
  i: Integer;
  j: Double;
 
begin
 
  for i := 1 to 22 do
    write(nonsqr(i), ' ');
  Writeln;
 
  for i := 1 to 999999 do
  begin
    j := Sqrt(nonsqr(i));
    if (j = Floor(j)) then
      Writeln(i, 'Is Square');
  end;
end.