# a, b で全探索 # a, bが決まればそのときのp進数がどこまで行けるかも決まるはず # p進数分数は、[a,b] (in p) / [p-1,p-1] (in p)と考えればいい # https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12186530002 # 二分探索で高速化 # https://science-log.com/python%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0tips%E9%9B%86/%E3%80%90python%E3%80%91%E8%A8%98%E6%95%B0%E6%B3%95%E3%81%AE%E5%A4%89%E6%8F%9B/ def N_to_Dec(digits, base): num = 0 for digit in digits: num = num * base + digit return num N = int(input()) ans = 0 for a in range(0, 10): for b in range(0, 10): if a == b: continue OK = 1 NG = 10**20 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 numerator*N > denominator: OK = mid else: NG = mid #print('a', a, 'b', b, 'OK', OK) ans += max(0, OK - max(a, b)) print(ans)