prime_big_omega_function_generalized.sf 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 27 November 2018
  4. # https://github.com/trizen
  5. # Generalization of the prime big omega function `Ω_m(n)`, for `m>=0`:
  6. #
  7. # Ω_m(n) = Sum_{p^k|n} Sum_{j=1..k} n^m / p^(j*m)
  8. # = Sum_{p^k|n} n^m * (p^(m*k) - 1) / (p^m - 1) / p^(m*k)
  9. #
  10. # Where the standard prime big omega function `Ω(n)` is equivalent with `Ω_0(n)`.
  11. # See also:
  12. # https://oeis.org/A001222
  13. # https://oeis.org/A095112
  14. # https://en.wikipedia.org/wiki/Prime_omega_function
  15. # https://trizenx.blogspot.com/2018/08/interesting-formulas-and-exercises-in.html
  16. func bigomega(n, m) {
  17. var total = 0
  18. for p,k in (n.factor_exp) {
  19. total += sum(1..k, {|j| n**m / p**(j*m) })
  20. }
  21. return total
  22. }
  23. say 25.of { bigomega(_, 0) }
  24. say 25.of { bigomega(_, 1) }
  25. say 25.of { bigomega(_, 2) }
  26. say 25.of { bigomega(_, 3) }
  27. say 25.of { bigomega(_, 4) }
  28. say 25.of { bigomega(_, 5) }
  29. __END__
  30. [0, 0, 1, 1, 2, 1, 2, 1, 3, 2, 2, 1, 3, 1, 2, 2, 4, 1, 3, 1, 3, 2, 2, 1, 4]
  31. [0, 0, 1, 1, 3, 1, 5, 1, 7, 4, 7, 1, 13, 1, 9, 8, 15, 1, 17, 1, 19, 10, 13, 1, 29]
  32. [0, 0, 1, 1, 5, 1, 13, 1, 21, 10, 29, 1, 61, 1, 53, 34, 85, 1, 121, 1, 141, 58, 125, 1, 253]
  33. [0, 0, 1, 1, 9, 1, 35, 1, 73, 28, 133, 1, 307, 1, 351, 152, 585, 1, 953, 1, 1189, 370, 1339, 1, 2483]
  34. [0, 0, 1, 1, 17, 1, 97, 1, 273, 82, 641, 1, 1633, 1, 2417, 706, 4369, 1, 7873, 1, 10881, 2482, 14657, 1, 26209]
  35. [0, 0, 1, 1, 33, 1, 275, 1, 1057, 244, 3157, 1, 9043, 1, 16839, 3368, 33825, 1, 66857, 1, 104149, 17050, 161083, 1, 289619]