23 lines
788 B
Plaintext
23 lines
788 B
Plaintext
// Lines that start with "//" are "comments" that are ignored
|
|
// by the computer. We use them to explain the code.
|
|
|
|
// Start by finding the smallest number that could possibly
|
|
// square to 269696. sqrt() returns the square root of a
|
|
// number, and floor() truncates any fractional part.
|
|
k = floor(sqrt(269696))
|
|
|
|
// Since 269696 is even, we are only going to consider even
|
|
// roots. We use the % (modulo) operator, which returns the
|
|
// remainder after division, to tell if k is odd; if so, we
|
|
// add 1 to make it even.
|
|
if k % 2 == 1 then k = k + 1
|
|
|
|
// Now we count up by 2 from k, until we find a number that,
|
|
// when squared, ends in 269696 (using % again).
|
|
while k^2 % 1000000 != 269696
|
|
k = k + 2
|
|
end while
|
|
|
|
// The first such number we find is our answer.
|
|
print k + "^2 = " + k^2
|