fork download
  1. f = -> n, m {
  2. (1...n).each_with_object(Hash.new {|h, k| h[k] = []}) {|b, acc|
  3. (b + 1..n).each {|a|
  4. c = a ** 3 - b ** 3
  5. acc[c] << [a, b]
  6. return acc[c] if acc[c].size == m
  7. }
  8. }.tap {break []}
  9. }
  10. p f.(10000, 5) # [[1134, 357], [1155, 504], [1246, 805], [2115, 2004], [4746, 4725]]
Time limit exceeded #stdin #stdout 5s 655256KB
stdin
Standard input is empty
stdout
Standard output is empty