#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int tab[N], tb[N], dig[N], n, dn[N];
vector<int> p[N];
void Solve() {
  int u, v;
  for (int i = 2; i <= n; i++) {
    if (p[i].size() != 0) continue;
    for (u = i, v = 1; u <= n && u >= 0; u *= i, v++) {
      for (int j = 1; 1LL * u * j <= 1LL * n; j++) {
        if (v > 1) p[u * j].pop_back();
        p[u * j].push_back(v);
      }
      if (1LL * u * i > n) break;
    }
  }
  for (int i = 1; i <= n; i++) {
    v = 1;
    for (int j = 0; j < p[i].size(); j++) {
      u = p[i][j];
      v *= u + 1;
    }
    tab[i] = v;
  }
  for (int i = 1; i < N; i++) {
    if (i < 10)
      dig[i] = i;
    else
      dig[i] = dig[dig[i / 10] + i % 10];
    if (i <= n) dn[dig[i]]++;
  }
  long long rlt(0);
  for (int i = 1; i <= n; i++) rlt -= tab[i];
  for (int i = 1; i <= min(9, n); i++) {
    u = dig[i * i];
    rlt += 1LL * dn[u] * dn[i] * dn[i];
    for (int j = 1; j <= min(9, n); j++) {
      if (i == j) continue;
      u = dig[i * j];
      rlt += 1LL * dn[u] * dn[i] * dn[j];
    }
  }
  cout << rlt << endl;
}
int main() {
  cin >> n;
  Solve();
}
