if !ENV['RUBY_THREAD_VM_STACK_SIZE'] exec({'RUBY_THREAD_VM_STACK_SIZE'=>'999999999'}, '/usr/bin/ruby', $0) else B = gets.to_i N = gets.to_i(B) # guchoku # str = ((0..999).map{|e|e.to_s(B)}*"") # puts str[0..50] # puts str[N] def dig(y, sz, ofs, w) # range "000".."999" i = y/w d = y%w i.to_s(B)[d] || "0" end def climb(x, sz, ofs, w) # range "100".."999" len = (sz-ofs)*w # p [x,sz,ofs,w] # p (ofs...sz).map{|e|e.to_s(B)} if x >= len climb(x-len, sz*B, sz, w+1) else # p B**(w-1) # ((ofs...sz).map{|e|e.to_s(B)}*"")[x] dig(x+B**(w-1)*w, sz, ofs, w) end end if N == 0 p 0 else puts climb(N-1, B, 1, 1) end end