071 Ordered fractions.sf 450 B

12345678910111213141516171819
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # By listing the set of reduced proper fractions for d ≤ 1,000,000 in ascending order of size, find the numerator of the fraction immediately to the left of 3/7.
  6. # https://projecteuler.net/problem=71
  7. # Runtime: 0.150s
  8. func before_numerator(b, n, d, m) {
  9. m -= (m+b % d)
  10. int(m/n + m/d - m/(n*d))
  11. }
  12. say before_numerator(2, 3, 7, 1e6)