All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Just Math
Another Divisibility Puzzle (Posted on 2006-09-25) Difficulty: 4 of 5
Determine the four smallest but different three digit positive decimal integers commencing with the same digit, such that their sum is divisible by precisely three of the said numbers.

What are the five smallest but different four digit positive decimal integers commencing with the same digit, such that their sum is divisible by precisely four of the said numbers?

See The Solution Submitted by K Sengupta    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution part 2: the only one | Comment 3 of 6 |

It's not only the smallest, but the only such set for part 2:

 1020  1428  1190  1785  1717              7140

The numbers on the left add to the numbers on the right.

The program shares factoring algorithms with that for Repeating Decimals.

DEFDBL A-Z
DECLARE SUB factor (num, s$)
DIM nFct
DIM fct(30)
DIM fact(100)
CLS
FOR nbr = 5000 TO 99999
 factor nbr, f$
 f$ = LTRIM$(f$) + " "
 nFct = 0
 DO
  ix = INSTR(f$, " ")
  IF ix > 0 THEN
   n = VAL(LEFT$(f$, ix - 1))
   f$ = MID$(f$, ix + 1)
   nFct = nFct + 1
   fct(nFct) = n
  END IF
 LOOP UNTIL f$ = ""
 npFct = 0: REDIM digCt(9)
 FOR combo = 1 TO INT(2 ^ nFct - .5)
  prod = 1: pwr2 = 1
  FOR j = 1 TO nFct
   IF pwr2 AND combo THEN prod = prod * fct(j)
   pwr2 = pwr2 * 2
  NEXT
  IF prod > 999 AND prod < 10000 THEN
   good = 1
   FOR i = 1 TO npFct
    IF fact(i) = prod THEN good = 0: EXIT FOR
   NEXT
   IF good THEN
     npFct = npFct + 1
     fact(npFct) = prod
     digCt(prod \ 1000) = digCt(prod \ 1000) + 1
   END IF
  END IF
 NEXT
 FOR d = 1 TO 9
  IF digCt(d) >= 4 THEN
   FOR n1 = 1 TO digCt(d) - 3
   FOR n2 = n1 + 1 TO digCt(d) - 2
   FOR n3 = n2 + 1 TO digCt(d) - 1
   FOR n4 = n3 + 1 TO digCt(d)
    upto = 0
    FOR i = 1 TO npFct
      IF fact(i) \ 1000 = d THEN
       upto = upto + 1
       IF upto = n1 OR upto = n2 OR upto = n3 OR upto = n4 THEN
         tot = tot + fact(i)
         n(upto) = fact(i)
         IF upto = n4 OR tot > nbr - 999 THEN EXIT FOR
       END IF
      END IF
    NEXT
    diff = nbr - tot
    IF diff \ 1000 = d THEN
      IF nbr MOD diff > 0 THEN
        FOR i = 1 TO 4
         PRINT n(i);
        NEXT
        PRINT diff, nbr
      END IF
    END IF
   NEXT
   NEXT
   NEXT
   NEXT
  END IF
 NEXT

NEXT

SUB factor (num, s$)
 s$ = "": 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 s$ = CHR$(27): EXIT SUB
 LOOP
 IF n > 1 THEN s$ = s$ + STR$(n)
 EXIT SUB

DivideIt:
 DO
  q = INT(n / dv)
  IF q * dv = n AND n > 0 THEN
    n = q
    s$ = s$ + STR$(dv)
    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
 RETURN
END SUB

 


  Posted by Charlie on 2006-09-25 14:37:59
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information