Find the largest palindrome which is a product of two 3-digit numbers.
CLS
FOR a = 100 TO 999
FOR b = a TO 999
prod = a * b
p$ = LTRIM$(STR$(prod))
pal = 1
FOR i = 1 TO LEN(p$) / 2
IF MID$(p$, i, 1) <> MID$(p$, LEN(p$) + 1 - i, 1) THEN pal = 0: EXIT FOR
NEXT
IF pal THEN
IF ct = 0 THEN PRINT a, b, prod
ct = ct + 1
IF prod >= prodmax THEN
asav = a: bsav = b: psav = prod
prodmax = prod
END IF
END IF
NEXT
NEXT
PRINT asav, bsav, psav
PRINT ct
PRINT
FOR a = 100 TO 999
FOR b = 100 TO 999
prod = a * b
p$ = LTRIM$(STR$(prod))
pal = 1
FOR i = 1 TO LEN(p$) / 2
IF MID$(p$, i, 1) <> MID$(p$, LEN(p$) + 1 - i, 1) THEN pal = 0: EXIT FOR
NEXT
IF pal THEN
IF prod = prodmax THEN
PRINT a, b, prod
END IF
END IF
NEXT
NEXT
101 101 10201
913 993 906609
1239
913 993 906609
993 913 906609
indicating the lowest is 101*101=10201 and the highest product is 913*993=906609 and there are 1239 products of two 3-digit integers with palindromic products, not counting reversals. The only way to achieve 906609 by multiplying 3-digit numbers is by 913*993 as 906609=3*11*83*331.
|
Posted by Charlie
on 2012-09-05 12:58:56 |