#include <bits/stdc++.h>
using namespace std;
int S[1000100], D[1000100], ile[20];
int c[1000100];
int main(void) {
  int n, m, i, j, k, l, w, a, b, C;
  long long res = 0LL;
  scanf("%d", &n);
  S[0] = D[0] = 0;
  for (i = (1); i < (1000002); ++i) {
    S[i] = i % 10 + S[i / 10];
    if (S[i] <= 9)
      D[i] = S[i];
    else
      D[i] = D[S[i]];
    if (i <= n) ++ile[D[i]];
  }
  for (C = 0; C < (10); ++C) {
    for (a = 0; a < (10); ++a) {
      for (b = 0; b < (10); ++b) {
        if (D[a * b] == C) res += ((long long)ile[C] * ile[a]) * ile[b];
      }
    }
  }
  for (i = 2; i <= 1010;) {
    for (j = i + i; j <= 1000010; j += i) c[j] = i;
    while (c[++i])
      ;
  }
  --res;
  for (i = (2); i < (n + 1); ++i) {
    j = i;
    l = -1;
    k = 0;
    w = 1;
    while (c[j] != 0) {
      if (c[j] != l) {
        w *= (k + 1);
        l = c[j];
        k = 1;
      } else
        ++k;
      j /= c[j];
    }
    if (j == l)
      w *= (k + 2);
    else
      w *= 2 * (k + 1);
    res -= w;
  }
  printf("%I64d\n", res);
  return 0;
}
