Hasty Briefsbeta

Closest Harmonic Number to an Integer

21 days ago
  • #Python
  • #Harmonic Numbers
  • #Numerical Approximation
  • Harmonic numbers Hn are never integers for n > 1.
  • Two problems to solve: accurately compute harmonic numbers and find n such that Hn is closest to a given integer m.
  • For small n, compute Hn directly; for large n, use an asymptotic approximation involving the Euler-Mascheroni constant γ.
  • To find n for Hn closest to m, approximate n as exp(m − γ).
  • Python code provided to compute Hn and find the nearest harmonic number to a given m.
  • Example usage: nearest_harmonic_number(10) returns 12366 with H(12366) ≈ 9.99996.
  • Code also works with real numbers, e.g., finding Hn closest to √20.