12345678910111213141516171819202122232425262728293031323334 |
- #!/usr/bin/ruby
- # Daniel "Trizen" Șuteu
- # License: GPLv3
- # Date: 01 May 2017
- # Edit: 28 June 2019
- # https://github.com/trizen
- # https://projecteuler.net/problem=581
- var B = 47
- var limit = 1109496723125 # A002072(π(47)) = A002072(15)
- var smooth_numbers = [1]
- for p in (primes(2, B)) {
- say "p = #{p}"
- for n in (smooth_numbers) {
- if (n*p <= limit) {
- smooth_numbers << n*p
- }
- }
- }
- var total = 0
- for n in (smooth_numbers) {
- if (is_smooth(n+1, B)) {
- total += n
- }
- }
- say total
|