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.




            NORMAL MODE IS INTEGER
            BOOLEAN FOUND
            FOUND = 0B
 
          R SEQUENCE OF NON-SQUARES FORMULA
          R FLOOR IS AUTOMATIC DUE TO INTEGER MATH
            INTERNAL FUNCTION NONSQR.(N) = N+(.5+SQRT.(N))
 
          R PRINT VALUES FOR 1..N..22            
            THROUGH SHOW, FOR N=1, 1, N.G.22
SHOW        PRINT FORMAT OUTFMT,N,NONSQR.(N)
            VECTOR VALUES OUTFMT = $I2,2H: ,I2*$
 
          R CHECK FOR NO SQUARES UP TO ONE MILLION
            THROUGH CHECK, FOR N=1, 1, N.GE.1000000
            X=NONSQR.(N)
            Y=SQRT.(X)
            WHENEVER Y*Y.E.X
                PRINT FORMAT FINDSQ,N,X
                FOUND = 1B 
CHECK       END OF CONDITIONAL
            WHENEVER .NOT. FOUND, PRINT FORMAT NOSQ
 
            VECTOR VALUES FINDSQ = $5HELEM ,I5,2H, ,I5,11H, IS SQUARE*$ 
            VECTOR VALUES NOSQ = $16HNO SQUARES FOUND*$
            END OF PROGRAM