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.




REAL :: n=22, nonSqr(n)
 
nonSqr = $ + FLOOR(0.5 + $^0.5)
WRITE() nonSqr
 
squares_found = 0
DO i = 1, 1E6
   non2 = i + FLOOR(0.5 + i^0.5)
   root = FLOOR( non2^0.5 )
   squares_found =  squares_found + (non2 == root*root)
ENDDO
WRITE(Name) squares_found
END