def solve(): def digit(x): res=0 while(x>0): res+=x%d x//=d return res def f(m,N): if m==0: return N return digit(f(m-1,N)) d,A,B=map(int,input().split()) if A==0: A+=1 if B==0: return 0 Ares,Bres=f(30,A),f(30,B) if (B-A+1)<=(d-1) and Ares