prime_power_counting_function.sf 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/ruby
  2. # A nice algorithm in terms of the prime-counting function for counting the number of prime powers <= n, with exponents >= 1.
  3. # See also:
  4. # https://oeis.org/A025528
  5. # https://en.wikipedia.org/wiki/Prime-counting_function
  6. # https://trizenx.blogspot.com/2018/11/partial-sums-of-arithmetical-functions.html
  7. func prime_power_count(n) {
  8. sum(1..n.ilog2, {|k|
  9. prime_count(n.iroot(k))
  10. })
  11. }
  12. for n in (1..27) {
  13. say "a(10^#{n}) = #{prime_power_count(10**n)}"
  14. }
  15. __END__
  16. a(10^1) = 7
  17. a(10^2) = 35
  18. a(10^3) = 193
  19. a(10^4) = 1280
  20. a(10^5) = 9700
  21. a(10^6) = 78734
  22. a(10^7) = 665134
  23. a(10^8) = 5762859
  24. a(10^9) = 50851223
  25. a(10^10) = 455062595
  26. a(10^11) = 4118082969
  27. a(10^12) = 37607992088
  28. a(10^13) = 346065767406
  29. a(10^14) = 3204942420923
  30. a(10^15) = 29844572385358
  31. a(10^16) = 279238346816392
  32. a(10^17) = 2623557174778438
  33. a(10^18) = 24739954338671299
  34. a(10^19) = 234057667428388198
  35. a(10^20) = 2220819603016308079
  36. a(10^21) = 21127269487386615271
  37. a(10^22) = 201467286693435354626
  38. a(10^23) = 1925320391619238700024
  39. a(10^24) = 18435599767386814628355
  40. a(10^25) = 176846309399257764978954
  41. a(10^26) = 1699246750872783231673649
  42. a(10^27) = 16352460426842732867857607