class Integer def divisor_list require 'prime' return [] if self <= 0 return [1] if self == 1 prime_division.map.with_index { |(base, k), i| s = i.zero? ? 0 : 1 (s..k).map { |n| base ** n } }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort end end N = gets.to_i ans = 0 N.divisor_list.each do |x| o = N / x cnt = 0 l = [x.bit_length, o.bit_length].max l.times do |i| if x[i] == 1 && o[i] == 1 cnt += 1 elsif x[i] == 1 && o[i] == 0 cnt = -1 break elsif x[i] == 0 && o[i] == 0 # noop elsif x[i] == 0 && o[i] == 0 # noop end end ans += 2 ** (cnt - 1) if 0 <= cnt end puts ans