DEFDBL A-Z
FOR i = 1 TO 99999
cube = i * i * i
cs$ = LTRIM$(STR$(cube))
pal = 1
FOR j = 1 TO LEN(cs$) / 2
IF MID$(cs$, j, 1) <> MID$(cs$, LEN(cs$) + 1 - j, 1) THEN pal = 0: EXIT FOR
NEXT
IF pal THEN PRINT cube; TAB(18); i
NEXT
finds
1 1
8 2
343 7
1331 11
1030301 101
1367631 111
1003003001 1001
10662526601 2201
1000300030001 10001
1030607060301 10101
1334996994331 11011
showing the first 11 palindromic cubes together with their cube roots. Only 10662526601 has a non-palindromic cube root: 2201.
To get to larger cubes without worrying about accuracy, we go to UBASIC:
10 for I=1 to 9999999
20 Cube=I*I*I
30 Cs$=cutspc(str(Cube))
40 Pal=1
50 for J=1 to int(len(Cs$)/2)
60 if mid(Cs$,J,1)<>mid(Cs$,len(Cs$)+1-J,1) then Pal=0
70 next
80 if Pal then print Cube;tab(28);I
90 next
finds
1 1
8 2
343 7
1331 11
1030301 101
1367631 111
1003003001 1001
10662526601 2201
1000300030001 10001
1030607060301 10101
1334996994331 11011
1000030000300001 100001
1033394994933301 101101
1331399339931331 110011
1000003000003000001 1000001
1003006007006003001 1001001
1331039930399301331 1100011
showing that even if we go to 19-position cubes, there is still only one palindromic cube of a non-palindromic number.
|
Posted by Charlie
on 2012-06-16 12:56:15 |