Discussion below (not as efficient as Charlie's but serves the purpose).
OPEN "c:\qb64\work\address.txt" FOR OUTPUT AS #1
FOR a = 1 TO 9
FOR b = 0 TO 9
FOR c = 0 TO 9
FOR d = 0 TO 9
FOR n = 0 TO 100
abcd = a * 10 ^ 3 + b * 10 ^ 2 + c * 10 + d
p = a ^ b * c ^ d - n
q = a ^ b * c ^ d + n
IF abcd = p THEN
PRINT "P"; abcd, n
PRINT #1, "P"; abcd, n
END IF
IF abcd = q THEN
PRINT "Q"; abcd, n
PRINT #1, "Q"; abcd, n
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
CLOSE 1
Data from program:
Q 1045 21
P 1264 32
Q 1364 68
Q 2145 97
P 2534 58
P 2592 0
Q 2592 0
P 3055 70
Q 3145 73
P 3353 22
Q 3651 6
P 4046 50
P 4084 12
Q 4145 49
Q 5145 25
Q 6145 1
P 6451 29
P 7145 23
P 8145 47
Q 8227 35
P 9145 71
"m" and "n" are defined in the problem but no differentiation has been made in the program. such values need to be accounted for in the data list.
P is "my address" and "n" is minimal but greater than 0.
Q is "my cousin" and "n" is minimal but greater than 1.
For those stipulations P is 4084 (n=12) and Q is 3651 (n=6).
|
Posted by brianjn
on 2012-10-28 20:47:24 |