#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 9;
int n, d[N];
int digit(int x) {
  int s = 0;
  while (x > 0) {
    s += x % 10;
    x /= 10;
  }
  return s;
}
vector<int> b[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i < 10; ++i) d[i] = i;
  for (int i = 10; i < N; ++i) d[i] = d[digit(i)];
  for (int i = 1; i <= n; ++i) b[d[i]].emplace_back(i);
  long long ans = 0;
  for (int i = 1, cnt; i <= n; ++i) {
    for (int j = 1; j < 10; ++j)
      if (!b[j].empty()) {
        cnt = upper_bound(b[j].begin(), b[j].end(), n / i) - b[j].begin();
        ans += (long long)b[j].size() * b[d[d[i] * j]].size() - cnt;
      }
  }
  cout << ans << '\n';
}
