X = gets.to_i d = Array.new(X+1, 1) d[0] = 0 2.upto(X) {|i| if d[i] == 1 then d[i] = 2 (2*i).step(X, i) {|j| n = 1 k = j while k % i == 0 do n += 1 k /= i end d[j] *= n } end } 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}" }