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

Home > Numbers
A short list (Posted on 2018-12-11) Difficulty: 2 of 5
List all the positive integers which are equal to the sum of the digits of their respective cubes.

How many of them are prime?

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 2
 n    cube
 1    1  
 8    512  
17    4913  prime
18    5832  
26    17576  
27    19683  

Only 17 is prime.

The cube of a 3-digit number will have at most 9 digits, totaling at most 9*9 = 81, and similarly for larger numbers. Thus the above is complete.


 For n = 1 To 100
   DoEvents
   n3$ = LTrim(Str(n * n * n))
   t = 0
   For i = 1 To Len(n3)
     t = t + Val(Mid(n3, i, 1))
   Next
   If t = n Then
      Text1.Text = Text1.Text & n & "    " & n3 & "  "
      If prmdiv(n) = n And n > 1 Then Text1.Text = Text1.Text & "prime"
      Text1.Text = Text1.Text & crlf
   End If
 Next

Function prmdiv(num)
 Dim n, dv, q
 If num = 1 Then prmdiv = 1: Exit Function
 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
 Loop
 If n > 1 Then prmdiv = n
 Exit Function

DivideIt:
 Do
  q = Int(n / dv)
  If q * dv = n And n > 0 Then
    prmdiv = dv: Exit Function
   Else
    Exit Do
  End If
 Loop

 Return
End Function


  Posted by Charlie on 2018-12-11 11:08:27
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