# a, b が小さいのでa, bで全探索 # p進数分数は、[a,b] (in p) / [p-1,p-1] (in p)と考えればいい # https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12186530002 def N_to_Dec(digits, base): # digitsはリスト num = 0 for digit in digits: num = num * base + digit return num N = int(input()) ans = 0 for a in range(10): for b in range(10): if a != b: OK = 1 NG = 10**9+1 while (NG-OK)>1: mid = (NG+OK)//2 numerator = N_to_Dec([a, b], mid) denominator = N_to_Dec([mid-1, mid-1], mid) if N*numerator > denominator: OK = mid else: NG = mid ans += max(0, OK-max(a, b)) # p はa, bよりも大きい必要ある print(ans)