X = gets.to_i arr = [3, 20] (2..100).each do |i| arr[i] = 6 * arr[i-1] - arr[i-2] + 2 end arr.each do |a| b = a+1 c = Math.sqrt(a*a + b*b).floor if c.to_s.size == X (-10000..10000).each do |d| c2 = c+d if c2.to_s.size == X && a*a + b*b == c2*c2 puts [a, b, c].join(' ') exit end end end end