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 re: part 2: the only one -- part 1 variant | Comment 4 of 6 |
(In reply to part 2: the only one by Charlie)

A variant of the program for part 2 verifies that the solution already given for part 1 is also unique--that is, not only the smallest such set of numbers but the only such set:

108  180  135  117          540

DEFDBL A-Z
DECLARE SUB factor (num, s$)
DIM nFct
DIM fct(30)
DIM fact(100)
CLS
FOR nbr = 400 TO 5555
 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 > 99 AND prod < 1000 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 \ 100) = digCt(prod \ 100) + 1
   END IF
  END IF
 NEXT
 FOR d = 1 TO 9
  IF digCt(d) >= 3 THEN
   FOR n1 = 1 TO digCt(d) - 2
   FOR n2 = n1 + 1 TO digCt(d) - 1
   FOR n3 = n2 + 1 TO digCt(d)
    upto = 0
    FOR i = 1 TO npFct
      IF fact(i) \ 100 = d THEN
       upto = upto + 1
       IF upto = n1 OR upto = n2 OR upto = n3 THEN
         tot = tot + fact(i)
         n(upto) = fact(i)
         IF upto = n3 OR tot > nbr - 99 THEN EXIT FOR
       END IF
      END IF
    NEXT
    diff = nbr - tot
    IF diff \ 100 = d THEN
      IF nbr MOD diff > 0 THEN
        FOR i = 1 TO 3
         PRINT n(i);
        NEXT
        PRINT diff, nbr
      END IF
    END IF
   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:51:40
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
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