#include <bits/stdc++.h>
using namespace std;
int n;
int Sum(int x) {
  int res;
  res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
int Root(int x) {
  if (x <= 9) return Sum(x);
  return Root(Sum(x));
}
long long ans;
int q[20];
int p[1000010];
int pq;
bool pc[1000010];
int main() {
  int k;
  int c, g;
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    q[i % 9]++;
  }
  p[1] = 2;
  pq = 1;
  for (i = 3; i * i <= n; i += 2) {
    if (pc[i]) continue;
    pq++;
    p[pq] = i;
    for (j = 2 * i; j <= n; j += i) {
      pc[j] = 1;
    }
  }
  ans = 0;
  for (j = 0; j <= 8; j++) {
    for (i = 0; i <= 8; i++) {
      ans += (long long)q[i] * q[j] * q[i * j % 9];
    }
  }
  for (i = 1; i <= n; i++) {
    g = 1;
    k = i;
    for (j = 1; j <= pq; j++) {
      if (k == 1) break;
      if (p[j] > i) break;
      if (k % p[j] == 0) {
        c = 0;
        while (k % p[j] == 0) {
          c++;
          k /= p[j];
        }
        g = g * (c + 1);
      }
    }
    if (k != 1) {
      g = g * 2;
    }
    ans -= g;
  }
  printf("%lld\n", ans);
  return 0;
}
