#include <bits/stdc++.h>
using namespace std;
int a[1000001];
long long S[10];
int s(int x) {
  int ss = 0;
  while (x > 0) ss += x % 10, x /= 10;
  return ss < 10 ? ss : s(ss);
}
long long count_num(int x) {
  long long rt = 0;
  for (int i = (1); i < (10); i++)
    for (int j = (i); j < (10); j++)
      if (i == j) {
        if (s(i * j) == x) rt += S[i] * S[j];
      } else if (s(i * j) == x)
        rt += S[i] * S[j] * 2ll;
  return rt;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) a[i] = s(i), S[a[i]]++;
  int real = 0;
  for (int j = (1); j < (n + 1); j++) {
    int k = 1;
    while (j * k <= n) {
      if (a[j * k] == a[a[j] * a[k]]) real++;
      k++;
    }
  }
  long long rt = 0;
  for (int i = (1); i < (10); i++) rt += S[i] * count_num(i);
  rt -= real;
  cout << rt << endl;
  return 0;
}
