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

Home > Just Math
Mean Muse II (Posted on 2014-07-06) Difficulty: 3 of 5
Determine the smallest positive integer n ≥ 2 for which the respective arithmetic, geometric, and harmonic means of T(n) and S(n) are all integers, where T(n) is the totient function and S(n) is the sum of divisors function.

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 1 of 1
DefDbl A-Z
Dim crlf$
Dim fct(20, 1), sumfact, f, dvsr

Private Sub Form_Load()
 ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
 DoEvents
 For n = 2 To 999
   f = factor(n)
   sumfact = 0
   dvsr = 1
   addIn 1
   p = phi(n)
   If (sumfact + p) Mod 2 = 0 Then
    sq = sumfact * p
    sr = Int(Sqr(sq) + 0.5)
    If sr * sr = sq Then
      hm = 1 / (1 / sumfact + 1 / p)
      hmround = Int(hm + 0.5)
      If Abs(hm - hmround) < 0.00001 Then
       Text1.Text = Text1.Text & Str(n) & Str(sumfact) & Str(p) & Str(hm) & crlf
      End If
    End If
   End If
   DoEvents
 Next
 Text1.Text = Text1.Text & "done"
End Sub

Function gcd(a, b)
  x = a: y = b
  Do
   z = x Mod y
   x = y: y = z
  Loop Until z = 0
  gcd = x
End Function
Function phi(n)
 tot = 0
 For i = 1 To n
  If gcd(i, n) = 1 Then tot = tot + 1
 Next
 phi = tot
End Function
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
Sub addIn(wh)
  For i = 0 To fct(wh, 1)
    pwr = Int(fct(wh, 0) ^ i + 0.5)
    dvsr = dvsr * pwr
    
    If wh = f Then
      sumfact = sumfact + dvsr
    Else
      addIn wh + 1
    End If
    
    dvsr = dvsr / pwr
  Next i
End Sub

finds
  
  n S(n) T(n) harm mean
 248 480 120 96
 264 720 80 72
 418 720 180 144
 477 702 312 216

so the answer is 248.



  Posted by Charlie on 2014-07-07 13:27:19
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