Product of 2 numbers equals sum of numbers between them
Some notes:


Use 2 spaces for indentation.
mul = 0 No need to define variables in Ruby.
@x = x. @name is a instance variable, but there is no class here. Use only local variables.
(1..n).reject {|n| n == x || n == y}.inject(&amp;:+). That's very slow, you should pre-compute the sum before, and just subtract the two elements in every loop.
last_arr &lt;&lt; (@x,@y = @y,@x). Only the last pair is reversed?
Make functions/methods return something.
You can use the simple formula n * (n + 1) / 2 for the sum of (1..n).
Your code is very, very imperative. For mathematical problems (if not for all), favor a functional style (immutable data-structures)


I'd write:

def get_pairs(n)
  range_sum = (n * (n + 1)) / 2
  pairs = (1..n).to_a.combination(2)
  matching_pairs = pairs.select { |x, y| x * y == range_sum - x - y }
  matching_pairs.flat_map { |x, y| [[x, y], [y, x]] }
end

p get_pairs(26) #=&gt; [[15, 21], [21, 15]]


With n = 500 it takes ~0.1s in my machine. If this is not still fast enough, you can still filter out pair values on the range that are too small to possibly match the sum range.