X = gets.to_i d = Array.new(X+1, 2) d[0] = 0 d[1] = 1 2.upto(X) {|i| (2*i).step(X, i) {|j| d[j] += 1 } } min = X minpair = nil 1.upto(X/2) {|a| b = X - a v = (a - d[a] - b + d[b]).abs if min > v then min = v minpair = a == b ? [[a, b]] : [[a, b], [b, a]] elsif min == v then minpair << [a, b] minpair << [b, a] if a != b end } minpair.sort_by{|x| x[0]}.each {|a, b| puts "#{a} #{b}" }