#!/usr/bin/env crystal lib C;fun strtoll(s: UInt8*,p: UInt8*,b: Int32): Int64;end starting=1_i64 base=10 while (s=gets)!=nil n=C.strtoll(s.not_nil!,nil,10)+starting-2 digits=1_i64 expbase=1_i64 while (x=digits*expbase*(base-1))<=n digits+=1 expbase*=base n-=x end num=expbase+n/digits d=digits-1-n%digits d.times{num/=base} puts num%base end