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)
    LET nonSquare = n + INT(0.5 + SQR(n))
END FUNCTION
 
! Display first 22 values
PRINT "The first 22 numbers generated by the sequence are : "
FOR i = 1 TO 22
    PRINT nonSquare(i); " ";
NEXT i
PRINT
 
! Check FOR squares up TO one million
LET found = 0
FOR i = 1 TO 1e6
    LET j = SQR(nonSquare(i))
    IF j = INT(j) THEN
       LET found = 1
       PRINT i, " square numbers found"
       EXIT FOR
    END IF
NEXT i
IF found = 0 THEN PRINT "No squares found"
END