32 lines
704 B
Text
32 lines
704 B
Text
// Rosetta Code problem: https://rosettacode.org/wiki/Square_but_not_cube
|
|
// by Jjuanhdez, 10/2022
|
|
|
|
count = 0 : n = 2
|
|
repeat
|
|
if isPow(n, 2) and not isPow(n, 3) then
|
|
print n, " ";
|
|
count = count + 1
|
|
fi
|
|
n = n + 1
|
|
until count = 30
|
|
print
|
|
|
|
count = 0 : n = 2
|
|
repeat
|
|
if isPow(n, 2) and isPow(n, 3) then
|
|
print n, " ";
|
|
count = count + 1
|
|
fi
|
|
n = n + 1
|
|
until count = 3
|
|
print
|
|
end
|
|
|
|
sub isPow(n, q)
|
|
//tests if the number n is the q'th power of some other integer
|
|
r = int(n^(1.0/q))
|
|
for i = r-1 to r+1 //there might be a bit of floating point nonsense, so test adjacent numbers also
|
|
if i^q = n return true
|
|
next i
|
|
return false
|
|
end sub
|