581 47-smooth triangular numbers.sf 539 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 01 May 2017
  5. # Edit: 28 June 2019
  6. # https://github.com/trizen
  7. # https://projecteuler.net/problem=581
  8. var B = 47
  9. var limit = 1109496723125 # A002072(π(47)) = A002072(15)
  10. var smooth_numbers = [1]
  11. for p in (primes(2, B)) {
  12. say "p = #{p}"
  13. for n in (smooth_numbers) {
  14. if (n*p <= limit) {
  15. smooth_numbers << n*p
  16. }
  17. }
  18. }
  19. var total = 0
  20. for n in (smooth_numbers) {
  21. if (is_smooth(n+1, B)) {
  22. total += n
  23. }
  24. }
  25. say total