#include <bits/stdc++.h>
using namespace std;
int inf = 1 << 30;
long long d[1000001];
long long c[10];
int main() {
  d[0] = 0;
  int n;
  cin >> n;
  for (int i = 0; i < 10; i++) c[i] = 0;
  for (int i = 1; i < 1000001; i++) {
    int x = i;
    int s = 0;
    while (x) {
      s += x % 10;
      x /= 10;
    }
    if (s <= 9)
      d[i] = s;
    else
      d[i] = d[s];
    if (i <= n) c[d[i]]++;
  }
  long long x = 0, y = 0;
  for (int A = 1; A < n + 1; A++)
    for (int B = 1; A * B <= n; B++) {
      x += d[A * B] == d[d[A] * d[B]];
    }
  for (int a = 0; a < 10; a++)
    for (int b = 0; b < 10; b++) y += c[a] * c[b] * c[d[a * b]];
  cout << y - x << endl;
}
