[Problem](http://www.codewars.com/kata/is-my-friend-cheating/javascript):

> 
> Find all the pairs (a, b) whose product is equal to the sum of all numbers in the sequence [1..n] excluding both a and b.
> 
> 
> 

I have made code for one program and need refactoring for code to get execution in less time. I am currently getting 13 sec for 500 number range.

```
def get_correct_array(n)
 beginning_time = Time.now
 puts " Begin with #{Time.now}"
 mul = 0
 arr = []
 last_arr = []

(1..n).each do |x|

 (x+1..n).each do |y|

    mul = x * y
    result = (1..n).reject {|n| n == x || n == y}.inject(&:+)
    if result == mul
        arr.concat([x,y])
        @x = x
        @y = y
    end
 end
end

last_arr << arr

if arr != []
 last_arr << (@x,@y = @y,@x)
end
if arr == []
 []
end

end_time = Time.now
puts " Ended with #{Time.now}"
puts "Time Elapsed -> #{(end_time - beginning_time)}"
p last_arr
end

```