Task

Show the first   30   positive integers which are squares but not cubes of such integers.

Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.




function is_pow(n as integer, q as integer) as boolean
    'tests if the number n is the q'th power of some other integer
    dim as integer r = int( n^(1.0/q) )
    for i as integer = r-1 to r+1   'there might be a bit of floating point nonsense, so test adjacent numbers also
       if i^q = n then return true
    next i
    return false
 
end function
 
dim as integer count = 0, n = 2
do
    if is_pow( n, 2 ) and not is_pow( n, 3 ) then
        print n;" ";
        count += 1
    end if
    n += 1
loop until count = 30
print
count = 0
n = 2
do
    if is_pow( n, 2 ) and is_pow( n, 3 ) then
        print n;" ";
        count += 1
    end if
    n += 1
loop until count = 3
print