n = gets.to_i fel = Array.new 6.times do |x| f = 2 ** (2 ** x) + 1; if f > n break end fel.push(f) end x = 0 res = 0 lim = 2 ** fel.length a = Array.new while true do m = 2 ** x if m > n break end lim.times do |i| s = i.to_s(2) q = m 0.upto(s.length - 1) do |j| if s[j] == "1" q *= fel[s.length - j - 1] end end if q >= 3 && q <= n res += 1 end end x += 1 end puts res