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

Home > Just Math
Perfect Power Puzzle (Posted on 2015-07-29) Difficulty: 2 of 5
Find all possible 3-digit positive perfect powers that are divisible by the sum of their respective digits.

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

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 2 of 7 |
The program checks that the GCD of the powers of the prime factors is greater than 1. That GCD is the power.

  n      as pwr  s.o.d.
100      10^2  1
144      12^2  9
216      6^3    9
225      15^2  9
243      3^5    9
324      18^2  9
400      20^2  4
441      21^2  9
512      2^9    8
576      24^2 18
900      30^2  9

from

DefDbl A-Z
Dim fct(20, 1), crlf$


Private Sub Form_Load()
 Text1.Text = ""
 crlf = Chr(13) & Chr(10)

 For n = 100 To 999
   f = factor(n)
   g = fct(1, 1)
   For i = 2 To f
     g = gcd(g, fct(i, 1))
   Next
   If g > 1 Then
     If n Mod sod(n) = 0 Then
       Text1.Text = Text1.Text & n & "      " & n ^ (1 / g) & "^" & (g) & Str(sod(n)) & crlf
     End If
   End If
 Next

Text1.Text = Text1.Text & "done"
  
End Sub
Function factor(num)
 diffCt = 0: good = 1
 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 Function
 Loop
 If n > 1 Then diffCt = diffCt + 1: fct(diffCt, 0) = n: fct(diffCt, 1) = 1
 factor = diffCt
 Exit Function

DivideIt:
 cnt = 0
 Do
  q = Int(n / dv)
  If q * dv = n And n > 0 Then
    n = q: cnt = cnt + 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 cnt > 0 Then
   diffCt = diffCt + 1
   fct(diffCt, 0) = dv
   fct(diffCt, 1) = cnt
 End If
 Return
End Function

Function gcd(a, b)
  x = a: y = b
  Do
   q = Int(x / y)
   z = x - q * y
   x = y: y = z
  Loop Until z = 0
  gcd = x
End Function

Function sod(n)
  s$ = LTrim(Str(n))
  tot = 0
  For i = 1 To Len(s$)
   tot = tot + Val(Mid(s$, i, 1))
  Next
  sod = tot
End Function


  Posted by Charlie on 2015-07-29 09:58:22
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 (6)
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