INF = 10 ** 12 def div_size(n) res = 0 i = 1 while i * i <= n if n % i == 0 if n / i != i res += 2 else res += 1 end end i += 1 end return res end X = gets.to_i a = X / 2 b = (X + 1) / 2 pre = INF ans = [] # binding.pry while a >= 0 || b <= X avalue = a - div_size(a) bvalue = b - div_size(b) dist = (avalue - bvalue).abs if pre > dist (ans = []) << [a, b] << [b, a] pre = dist elsif pre == dist ans << [a, b] << [b, a] end a -= 1 b += 1 end ans.sort_by!{|x, y|x}.each do |an| puts "#{an[0]} #{an[1]}" end