Powerful numbers (4,8,9,16,25,27... )are defined as follows: if a prime p divides n then p2 must also divide n.
(8,9) is a couple of two consecutive numbers,both of them being powerful.
Find another pair(s) like that.
The more the merrier!!
DECLARE FUNCTION powerful# (num#)
DEFDBL A-Z
CLS
FOR i = 1 TO 1000000
IF powerful(i) THEN
IF prev THEN PRINT i - 1; i
prev = 1
ELSE
prev = 0
END IF
NEXT
FUNCTION powerful (num)
n = ABS(num): IF n > 0 THEN limit = SQR(n): ELSE limit = 0
IF limit <> INT(limit) THEN limit = INT(limit + 1)
dv = 2: GOSUB DivideIt
dv = 3: GOSUB DivideIt
dv = 5: GOSUB DivideIt
dv = 7
DO UNTIL dv > limit
GOSUB DivideIt: dv = dv + 4 '11
GOSUB DivideIt: dv = dv + 2 '13
GOSUB DivideIt: dv = dv + 4 '17
GOSUB DivideIt: dv = dv + 2 '19
GOSUB DivideIt: dv = dv + 4 '23
GOSUB DivideIt: dv = dv + 6 '29
GOSUB DivideIt: dv = dv + 2 '31
GOSUB DivideIt: dv = dv + 6 '37
IF INKEY$ = CHR$(27) THEN EXIT FUNCTION
LOOP
IF n > 1 THEN powerful = 0: ELSE powerful = 1
EXIT FUNCTION
DivideIt:
rep = 0
DO
q = INT(n / dv)
IF q * dv = n AND n > 0 THEN
n = q
rep = rep + 1
IF n > 0 THEN limit = SQR(n): ELSE limit = 0
IF limit <> INT(limit) THEN limit = INT(limit + 1)
ELSE
EXIT DO
END IF
LOOP
IF rep = 1 THEN powerful = 0: EXIT FUNCTION
RETURN
END FUNCTION
finds
8 9
288 289
675 676
9800 9801
12167 12168
235224 235225
332928 332929
465124 465125
giving all such pairs that lie under one million.
The powerful function is a modification of an algorithm for factoring into primes.
|
Posted by Charlie
on 2010-08-09 14:29:07 |