def div_ceil (l, r) q = l / r ; q += 1 if l % r != 0 ; q end def binpow (x) if x == 0 then 1 else lowest = ((x % 2 == 0) ? 1 : $kd) lowest * (binpow(x / 2) ** 2) end end def calc (n) ($a - 1) * binpow(n) + (binpow(n + 1) - 1) / $k end def init_r maybe = 1 maybe *= 2 while calc(maybe) < $m maybe end def solve if $k == 0 then return $m - $a end $kd = $k + 1 l = 0 r = init_r while l != r if calc((l + r) / 2) < $m then l = div_ceil(l + r, 2) else r = (l + r) / 2 end end l end $m = gets.chomp.to_i(10) $a, $k = gets.chomp.split(' ').map{|e| e.to_i(10)} puts solve