Since 2^36 exceeds any 10-digit number we need check no higher n.
Once p^n exceeds a 5-digit number for a given n, we need not check that nor succeeding p, as q is larger and the two powers together will have more than 10 digits.
The following program checks all the possibilities within those constraints:
DEFDBL A-Z
CLS
FOR n = 3 TO 36
p = 0
DO
p = p + 1
ppwr = INT(p ^ n + .5)
part1$ = LTRIM$(STR$(ppwr))
IF LEN(part1$) > 5 THEN EXIT DO
good = 1
FOR i = 1 TO LEN(part1$) - 1
IF INSTR(i + 1, part1$, MID$(part1$, i, 1)) > 0 THEN good = 0: EXIT FOR
NEXT
IF good THEN
q = p
DO
q = q + 1
qpwr = INT(q ^ n + .5)
part2$ = LTRIM$(STR$(qpwr))
w$ = part1$ + part2$
IF LEN(w$) > 10 THEN EXIT DO
good = 1
FOR i = 1 TO LEN(w$) - 1
IF INSTR(i + 1, w$, MID$(w$, i, 1)) > 0 THEN good = 0: EXIT FOR
NEXT
IF good AND LEN(w$) = 10 THEN PRINT p, q, n, part1$; " "; part2$
LOOP
END IF
LOOP
NEXT
finding only
21 93 3 9261 804357
meaning (P, Q, N) = (21, 93, 3)
and 21^3 = 9261 and 93^3 = 804357.
|
Posted by Charlie
on 2009-05-12 15:11:21 |