import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;

public class Main implements Runnable {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Thread(new Main()).start();
	}

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			run1();
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}

	int nextInt(StreamTokenizer st) throws IOException {
		st.nextToken();
		return (int) st.nval;
	}

	private List<Integer> kmp(String x, String a) {
		String s = a + "$" + x;
		int[] oppa = new int[s.length()];
		oppa[0] = 0;
		int tmp = 0;
		List<Integer> res = new ArrayList<Integer>();
		for (int i = 1; i < s.length(); i++) {
			while (tmp != 0 && s.charAt(tmp) != s.charAt(i)) {
				// System.out.println(i + " " + tmp);
				tmp = oppa[tmp - 1];
			}
			if (s.charAt(tmp) == s.charAt(i))
				tmp++;
			oppa[i] = tmp;
			if (tmp == a.length()) {
				res.add(i - a.length() - a.length());
			}
		}
		return res;
	}

	double nextDouble(StreamTokenizer st) throws IOException {
		st.nextToken();
		return st.nval;
	}

	String nextLine(StreamTokenizer st) throws IOException {
		st.nextToken();
		return st.sval;
	}

	public void run1() throws IOException {
		Scanner sc = new Scanner(new InputStreamReader(System.in));
		// Scanner sc = new Scanner(new FileReader("input.txt"));
		int n = sc.nextInt();
		long[] num = new long[9];
		for (int i = 1; i <= n; i++)
			num[i % 9]++;
		long res = 0;
		for (int a = 0; a < 9; a++)
			for (int b = 0; b < 9; b++) {
				res += num[a] * num[b] * num[a * b % 9];
			}
		for (int a = 1; a <= n; a++)
			res -= n / a;
		System.out.println(res);
	}
}

import java.io.*;
import java.util.StringTokenizer;

/**
 * CodeForces 10C - Digital Root
 * Created by Darren on 14-10-11.
 */
public class C {
    Reader in = new Reader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        new C().run();
    }

    int n;

    void run() throws IOException {
        n = in.nextInt();
        int[] cnt = new int[10];
        for (int i = 1; i <= (n-1)%9+1; i++)
            cnt[i] = (n+8) / 9;
        for (int i = (n-1)%9+2; i <= 9; i++)
            cnt[i] = n / 9;

        long result = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++)
                result += (long)cnt[i] * cnt[j] * cnt[(i*j-1)%9+1];
        }
        for (int i = 1; i <= n; i++)
            result -= n / i;
        out.println(result);
        out.flush();
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public Reader(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /** get next word */
        String nextToken() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer( reader.readLine() );
            }
            return tokenizer.nextToken();
        }

        String readLine() throws IOException {
            return reader.readLine();
        }

        int nextInt() throws IOException {
            return Integer.parseInt( nextToken() );
        }

        long nextLong() throws IOException {
            return Long.parseLong( nextToken() );
        }

        double nextDouble() throws IOException {
            return Double.parseDouble( nextToken() );
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class DigitalRoot {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws IOException {

		int n = Integer.parseInt(br.readLine());

		/* Problem statement says (i*j == k) => (d(d(i)*d(j)) == d(k)) so we
		 * only need to check whether !(i*j == k) && (d(d(i)*d(j)) == d(k)).
		 * It's computationally cheaper to calculate A: how many times
		 * (d(d(i)*d(j)) == d(k)) is true and discount B: how many times
		 * (i*j == k) is true.
		 */
		pw.println(A(n)-B(n));
		pw.close();
	}

	private static int B(int n) {
		int sol = 0;
		for (int i = 1; i <= n; i++) {
			sol += n/i;
		}
		return sol;
	}

	private static long A(int n) {
		long[] cnt = new long[10];
		for (int i = 1; i < cnt.length; i++) {
			cnt[i] = (n+9-i)/9;
		}
		long sol = 0;
		for (int i = 1; i < cnt.length; i++) {
			for (int j = 1; j < cnt.length; j++) {
				for (int k = 1; k < cnt.length; k++) {
					if (i*j%9 == k%9) {
						sol += cnt[i]*cnt[j]*cnt[k];
					}
				}
			}
		}
		return sol;
	}
}

import java.io.*;
import java.util.*;

public class CF {

	void realSolve() {
		// for (int n = 1; n <= 100; n++) {
		int n = in.nextInt();
		int[] ans = new int[Math.max(100, n + 1)];
		for (int i = 0; i < 10; i++)
			ans[i] = i;
		for (int i = 1; i < Math.max(100, n + 1); i++) {
			ans[i] = ans[(ans[i / 10] + i % 10)];
		}
		int[] sum = new int[10];
		for (int i = 1; i <= n; i++)
			sum[ans[i]]++;
		long res = 0;
		for (int f = 1; f < 10; f++) {
			for (int s = 1; s < 10; s++) {
				long cur = sum[f];
				cur *= sum[s];
				int th = ans[f * s];
				cur *= sum[th];
				res += cur;
			}
		}
		for (int i = 1; i <= n; i++) {
			int max = n / i;
			res -= max;
		}
		// out.println(n + ": " + res);
		out.println(res);
		// }
	}

	private class InputReader {
		StringTokenizer st;
		BufferedReader br;

		public InputReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public InputReader(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s;
				try {
					s = br.readLine();
				} catch (IOException e) {
					return null;
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		boolean hasMoreElements() {
			while (st == null || !st.hasMoreElements()) {
				String s;
				try {
					s = br.readLine();
				} catch (IOException e) {
					return false;
				}
				st = new StringTokenizer(s);
			}
			return st.hasMoreElements();
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	InputReader in;
	PrintWriter out;

	void solve() {
		in = new InputReader(new File("object.in"));
		try {
			out = new PrintWriter(new File("object.out"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		realSolve();

		out.close();
	}

	void solveIO() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		realSolve();

		out.close();

	}

	public static void main(String[] args) {
		new CF().solveIO();
	}
}

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		BufferedReader kek = new BufferedReader(new InputStreamReader(System.in));
		//Scanner skek = new Scanner(System.in);
		PrintWriter outkek = new PrintWriter(System.out);

		int N = Integer.parseInt(kek.readLine());
		long[] D = new long[10];
		long res = 0;

		for(int i = 1; i <= N; i++){
			D[i % 9]++;
		}

		for(int i = 1; i <= N; i++){
			res -= N / i;
		}

		for(int i = 0; i < 9; i++){
			for(int j = 0; j < 9; j++){
				long temp = D[i] * D[j] * D[i * j % 9];
				res += temp;
			}
		}

		outkek.println(res);

		kek.close();
		outkek.close();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(f.readLine());
        int[] a = new int[9];
        for (int i = 0; i < 9; i++)
            a[i] = n/9;
        for (int i = 9*(n/9)+1; i <= n; i++)
            a[i%9]++;
        long sum = 0;
        for (int x = 0; x < 9; x++)
            for (int y = 0; y < 9; y++)
                sum += 1l*a[x]*a[y]*a[(x*y)%9];
        for (int x = 1; x <= n; x++)
            sum -= n/x;

        System.out.println(sum);
    }
}

//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class C {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    void solve() throws IOException {
        int n = nextInt();
        int[] d = new int[Math.max(n + 1, 9 * 9 + 1)];
        for(int i = 1; i < d.length; i++) {
            d[i] = i < 10 ? i : d[i / 10 + i % 10];
        }
        int[] smallestPrimeDivisor = new int[n + 1];
        for(int i = 2; i <= n; i++) {
            if(smallestPrimeDivisor[i] == 0) {
                smallestPrimeDivisor[i] = i;
                if(1l * i * i > n) {
                    continue;
                }
                for(int j = i * i; j <= n; j += i) {
                    if(smallestPrimeDivisor[j] == 0) {
                        smallestPrimeDivisor[j] = i;
                    }
                }
            }
        }
        int[] numberOfSmallestPrimeDivisors = new int[n + 1];
        int[] numberOfDivisors = new int[n + 1];
        numberOfDivisors[1] = 1;
        for(int i = 2; i <= n; i++) {
            int prev = i / smallestPrimeDivisor[i];
            numberOfSmallestPrimeDivisors[i] = smallestPrimeDivisor[i] == smallestPrimeDivisor[prev] ?
                    numberOfSmallestPrimeDivisors[prev] + 1 : 1;
            numberOfDivisors[i] = smallestPrimeDivisor[i] == smallestPrimeDivisor[prev] ?
                    numberOfDivisors[prev] / numberOfSmallestPrimeDivisors[i] * (numberOfSmallestPrimeDivisors[i] + 1) :
                    numberOfDivisors[prev] * 2;
        }
        int[] freq = new int[10];
        for (int i = 1; i <= n; i++) {
            freq[d[i]]++;
        }
        long[] foo = new long[10];
        for(int c = 1; c < 10; c++) {
            for(int a = 1; a < 10; a++) {
                for(int b = 1; b < 10; b++) {
                    if(d[c] == d[a * b]) {
                        foo[c] += 1L * freq[a] * freq[b];
//                        if(a == b) {
//                            foo[c] -= freq[a];
//                        }
                    }
                }
            }
        }
        long ans = 0;
        for(int i = 1; i <= n; i++) {
            ans += foo[d[i]] - numberOfDivisors[i];
        }
        writer.println(ans);
        writer.close();
    }

    public static void main(String[] args) throws IOException {
        new C().solve();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.StringTokenizer;

//O(N)
public class Main10C {

    private FastScanner in;
    private PrintWriter out;

    public void solve() throws IOException {
        int N = in.nextInt();
        byte[] digitRoot = new byte[Math.max(N + 1, 100)];
        for (int i = 1; i < digitRoot.length; i++) {
            int s = 0;
            int k = i;
            while (k >= 10) {
                s = s + k % 10;
                k = k / 10;
            }
            s = s + k;
            if (s < 10) {
                digitRoot[i] = (byte) s;
            }
            else {
                digitRoot[i] = digitRoot[s];
            }
        }

        int[] digitRootCount = new int[10];
        for (int i = 1; i <= N; i++) {
            digitRootCount[digitRoot[i]]++;
        }

        BigDecimal countAll = new BigDecimal(0);
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                for (int k = 1; k <= 9; k++) {
                    if (digitRoot[j * k] == i) {
                        long temp = digitRootCount[i];
                        temp *= digitRootCount[j];
                        temp *= digitRootCount[k];
                        BigDecimal t = new BigDecimal(temp);
                        countAll = countAll.add(t);
                    }
                }
            }
        }

        long count = 0;
        for (int i = 1; i <= N; i++) {
            count += N / i;
        }

        out.println(countAll.subtract(new BigDecimal(count)));
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
            solve();
            out.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] arg) {
        new Main10C().run();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class MainC {

    private FastScanner in;
    private PrintWriter out;

    public void solve() throws IOException {
        int N = in.nextInt();
        byte[] digitRoot = new byte[Math.max(N + 1, 100)];
        for (int i = 1; i < digitRoot.length; i++) {
            int s = 0;
            int k = i;
            while (k >= 10) {
                s = s + k % 10;
                k = k / 10;
            }
            s = s + k;
            if (s < 10) {
                digitRoot[i] = (byte) s;
            }
            else {
                digitRoot[i] = digitRoot[s];
            }
        }

        int[] digitRootCount = new int[10];
        for (int i = 1; i <= N; i++) {
            digitRootCount[digitRoot[i]]++;
        }

        BigDecimal countAll = new BigDecimal(0);
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                for (int k = 1; k <= 9; k++) {
                    if (digitRoot[j * k] == i) {
                        long temp = digitRootCount[i];
                        temp *= digitRootCount[j];
                        temp *= digitRootCount[k];
                        BigDecimal t = new BigDecimal(temp);
                        countAll = countAll.add(t);
                    }
                }
            }
        }

        long count = 0;
        for (int i = 1; i <= N; i++) {
            count += NumberTheoryUtil.countFactors(i);
        }

        out.println(countAll.subtract(new BigDecimal(count)));
    }

    private static class NumberTheoryUtil {

        public static int countFactors(int N) {
            int res = 1;
            while (N % 2 == 0) {
                res++;
                N = N / 2;
            }
            int i = 3;
            while (N > 1) {
                while (N % i > 0 && i * i <= N) {
                    i = i + 2;
                }
                if (N % i == 0) {
                    int p = 1;
                    while (N % i == 0) {
                        p++;
                        N = N / i;
                    }
                    res = res * p;
                }
                else {
                    res = res * 2;
                    N = 1;
                }
            }
            return res;
        }
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
            solve();
            out.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] arg) {
        new MainC().run();
    }
}

import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

// Solution is at the bottom of code

public class ProblemC_010 implements Runnable{

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	OutputWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args){
		new Thread(null, new ProblemC_010(), "", 128 * (1L << 20)).start();
	}

	/////////////////////////////////////////////////////////////////////

	void init() throws FileNotFoundException{
		Locale.setDefault(Locale.US);

		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new OutputWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new OutputWriter("output.txt");
		}
	}

	////////////////////////////////////////////////////////////////

	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	void debug(Object... objects){
		if (ONLINE_JUDGE){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

	/////////////////////////////////////////////////////////////////////

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			Locale.setDefault(Locale.US);

			init();
			solve();

			out.close();
			time();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	/////////////////////////////////////////////////////////////////////

	String delim = " ";

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}

		return tok.nextToken(delim);
	}

	String readLine() throws IOException{
		return in.readLine();
	}

	/////////////////////////////////////////////////////////////////

	final char NOT_A_SYMBOL = '\0';

	char readChar() throws IOException{
		int intValue = in.read();

		if (intValue == -1){
			return NOT_A_SYMBOL;
		}

		return (char) intValue;
	}

	char[] readCharArray() throws IOException{
		return readLine().toCharArray();
	}

	/////////////////////////////////////////////////////////////////

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException{
		int[] array = new int[size];

		for (int index = 0; index < size; ++index){
			array[index] = readInt();
		}

		return array;
	}

	///////////////////////////////////////////////////////////////////

	long readLong() throws IOException{
		return Long.parseLong(readString());
	}

	long[] readLongArray(int size) throws IOException{
		long[] array = new long[size];

		for (int index = 0; index < size; ++index){
			array[index] = readLong();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}

	double[] readDoubleArray(int size) throws IOException{
		double[] array = new double[size];

		for (int index = 0; index < size; ++index){
			array[index] = readDouble();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	Point readPoint() throws IOException{
		return new Point(readInt(), readInt());
	}

	Point[] readPointArray(int size) throws IOException{
		Point[] array = new Point[size];

		for (int index = 0; index < size; ++index){
			array[index] = readPoint();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
	throws IOException{
		List<Integer>[] graph = new List[vertexNumber];

		for (int index = 0; index < vertexNumber; ++index){
			graph[index] = new ArrayList<Integer>();
		}

		while (edgeNumber-- > 0){
			int from = readInt() - 1;
			int to = readInt() - 1;

			graph[from].add(to);
			graph[to].add(from);
		}

		return graph;
	}

	/////////////////////////////////////////////////////////////////////

	class OutputWriter extends PrintWriter{

		final int DEFAULT_PRECISION = 12;

		int precision;
		String format, formatWithSpace;

		{
			precision = DEFAULT_PRECISION;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		public OutputWriter(OutputStream out) {
			super(out);
		}

		public OutputWriter(String fileName) throws FileNotFoundException {
			super(fileName);
		}

		public int getPrecision() {
			return precision;
		}

		public void setPrecision(int precision) {
			this.precision = precision;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		private String createFormat(int precision){
			return "%." + precision + "f";
		}

		@Override
		public void print(double d){
			printf(format, d);
		}

		public void printWithSpace(double d){
			printf(formatWithSpace, d);
		}

		public void printAll(double...d){
			for (int i = 0; i < d.length - 1; ++i){
				printWithSpace(d[i]);
			}

			print(d[d.length - 1]);
		}

		@Override
		public void println(double d){
			printlnAll(d);
		}

		public void printlnAll(double... d){
			printAll(d);
			println();
		}
	}

	/////////////////////////////////////////////////////////////////////

	int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

	boolean check(int index, int lim){
		return (0 <= index && index < lim);
	}

	/////////////////////////////////////////////////////////////////////

	void solve() throws IOException{
		int n = readInt();

		long[] count = new long[10];
		for (int i = 1; i <= 9; ++i){
			count[i] = count(i, n);
		}

		int[][] d = new int[10][10];
		for (int i = 1; i <= 9; ++i){
			for (int j = 1; j <= 9; ++j){
				d[i][j] = (i * j) % 9;
				if (d[i][j] == 0) d[i][j] = 9;
			}
		}

		long ans = 0;
		for (int a = 1, s = 1; a <= n; ++a, s = (s == 9? 1: s + 1)){
			int k = n / a;

			for (int b = 1; b <= 9; ++b){
				int c = d[s][b];

				long res = count[b] * count[c] - count(b, k);

//				long resStress = stress(a, b, c, n);

//				if (res != resStress){
//					System.err.println(a + " " + b + " " + res + " " + resStress);
//				}

				ans += res;
			}
		}

		out.println(ans);
	}

	int d(int x){
		int res = x % 9;

		return (res == 0? 9: res);
	}

	long count(int d, int n){
		long res = n / 9;

		int md = n % 9;
		if (md > 0 && md >= d) ++res;

		return res;
	}

	long stress(int a, int b, int c, int n){
		long res = 0;

		for (int i = b; i <= n; i += 9){
			for (int j = c; j <= n; j += 9){
				if (a * i != j){
					++res;
				}
			}
		}

		return res;
	}
}

import java.util.Scanner;
public final class DigitalRoot {
    private static int[] ds;

    private static int getDigitalRoot(int i) {
        char[] c = (new Integer(i)).toString().toCharArray();
        int sum = 0;
        for (int j = 0; j < c.length; j++) sum += c[j] - '0';
        if (sum <= 9) return ds[sum];
        else return ds[sum];
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        ds = new int[Math.max(N, 81) + 1];
        long[] counts = new long[10];
        for (int i = 1; i < 10; i++) ds[i] = i;
        for (int i = 10; i < Math.max(N, 81) + 1; i++) ds[i] = getDigitalRoot(i);
        for (int i = 1; i < N + 1; i++) counts[ds[i]]++;

        long total = 0;
        for (int i = 1; i < 10; i++)
            for (int j = 1; j < 10; j++)
                total += counts[ds[i * j]] * counts[i] * counts[j];

        for  (int i = 1; i <= N; i++) total -= N/i;
        System.out.println(total);
    }
}

import java.util.Scanner;
public final class DigitalRoot {
    private static int[] ds;

    private static int getDigitalRoot(int i) {
        char[] c = (new Integer(i)).toString().toCharArray();
        long sum = 0;
        for (int j = 0; j < c.length; j++) sum += c[j] - '0';
        if (sum <= 9) return ds[(int) sum];
        else return ds[(int) sum];
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        ds = new int[Math.max(N, 81) + 1];
        long[] counts = new long[10];
        for (int i = 1; i < 10; i++) ds[i] = i;
        for (int i = 10; i < Math.max(N, 81) + 1; i++) ds[i] = getDigitalRoot(i);
        for (int i = 1; i < N + 1; i++) counts[ds[i]]++;

        long total = 0;
        for (int i = 1; i < 10; i++)
            for (int j = 1; j < 10; j++)
                total += counts[ds[i * j]] * counts[i] * counts[j];

        for  (int i = 1; i <= N; i++) total -= N/i;
        System.out.println(total);
    }
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
 * 10:25 ~ 10:42
 *
 */
public class Main {
	public static int MOD = 20090711;
	public static void main(String[] argv) {
		FastScanner scan = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();

		int cnt[] = new int[10];
		for(int i = 1; i <= n; ++i){
			cnt[(i - 1) % 9 + 1]++;
		}
		long ret = 0;
		for(int a = 1; a < 10; ++a){
			for(int b = 1; b < 10; ++b){
				ret += (long) cnt[a] * cnt[b] * cnt[(a * b - 1) % 9 + 1];
			}
		}
		for(int a = 1; a <= n; ++a)
			ret -= (n / a);
		out.println(ret);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream is) {
			try {
				br = new BufferedReader(new InputStreamReader(is));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					return null;
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.valueOf(next());
		}
	}
}

import java.io.*;

public class C {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main (String[] args) throws IOException {
        long n = Integer.parseInt(br.readLine());
        long ans = 0;
        for (int a = 1; a <= 9; a++) {
            for (int b = 1; b <= 9; b++) {
                ans += f(n, a * b) * f(n, a) * f(n, b);
            }
        }
        // System.out.println(ans);
        for (int A = 1; A <= n; A++) {
            ans -= n / A;
        }
        System.out.println(ans);
    }
    private static long f (long n, long x) {
        long y = (x - 1) % 9 + 1;
        return y <= n ? 1 + (n - y) / 9 : 0;
    }
}

public class Main {
	public static void main(String[] args)
	{
		int N = (new java.util.Scanner(System.in).nextInt());
		int q = N / 9;
		int r = N % 9;

		long ans = 0;
		for (int i1 = 0; i1 < 9; i1++)
			for (int i2 = 0; i2 < 9; i2++)
				for (int i3 = 0; i3 < 9; i3++)
				{
					if((i1 * i2) % 9 == i3 % 9)
					{
						long a1 = q + ((r >= i1 && i1>0)?1:0);
						long a2 = q + ((r >= i2 && i2>0)?1:0);
						long a3 = q + ((r >= i3 && i3>0)?1:0);
						ans += a1 * a2 * a3;
					}
				}

		for (int i = 1; i <= N; i++)
			ans -= N / i;

		System.out.println(ans);
	}
}

import java.io.*;
import java.util.*;

public class Main {

	Scanner in;
	PrintWriter out;

	int divCount[];
	int d[];

	long countDD[]=new long[10];

	void prepare(){
		for (int i = 1; i < divCount.length; i++) {
			for (int j = i; j < divCount.length; j+=i){
				divCount[j]++;
			}
		}
	}

	void pp(){
		for (int i = 1; i < d.length; i++){
			int p = i;
			while (p >= 10) {
				p = p / 10 + p % 10;
			}
			d[i] = p;
			countDD[p]++;
		}

		for (int a = 0; a <= 9; a++) {
			for (int b = 0; b <= 9; b++){
				int val = a * b;
				while (val >= 10) {
					val = val / 10 + val % 10;
				}
				this.val[a][b] = val;
			}
		}

	}

	void precalc(int n){
		int ans = 0;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				for (int k = 1; k <= n; k++){
					int d1 = i / 10 + i % 10;
					int d2 = j / 10 + j % 10;
					int d3 = d1 * d2;
					while (d3 >= 10) {
						d3 = d3 / 10 + d3 % 10;
					}
					if (i * j != k && k % 10 + k/10 == d3) {
						ans++;
					}
				}
			}
		}
		out.println(ans);
	}

	int val[][] = new int[11][11];

	void solve(){
		int n = in.nextInt();
		divCount = new int[1+n];
		d = new int[1 + n];
		prepare();
		pp();

		//precalc(n);

		long ans = 0;

		for (int sqrt = 0; sqrt <= 9; sqrt++) {
			for (int a = 0; a <= 9; a++) {
				for (int b = 0; b <= 9; b++){
					if (val[a][b] == sqrt) {
						ans = ans + countDD[sqrt]*countDD[a]*countDD[b];
					}
				}
			}
		}

		for (int i = 1; i <= n; i++){
			ans -= divCount[i];
		}
		out.println(ans);
	}

	void run(){
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class trial
{
	static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input)
    {
        reader = new BufferedReader( new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static long nextInt() throws IOException
    {
        return Long.parseLong( next() );
    }
	static PrintWriter writer;
	static void outit(OutputStream outputStream)
	{
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}
	static void print(Object...objects) {
		for (int i = 0; i < objects.length; i++)
		{
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	static void println(Object...objects)
	{
		print(objects);
		writer.println();
	}

	static void close()
	{
		writer.close();
	}

	static void flush() {
		writer.flush();
	}
	public static void print_a(long [] a)
    {
    	for(long i : a)
    	{
    		print(i+" ") ;
    	}
    	println() ;
    }
    public static void main(String [] args) throws IOException
    {
    	init(System.in) ;
    	outit(System.out) ;
//    	int t = (int) nextInt() ;
//    	for(int i =0 ; i<t ; i++)
    	output() ;
        flush();
        close();
    }
    public static void output() throws IOException
    {
    	int n = (int)nextInt() ;
    	long [] ctr = new long[9] ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		ctr[i%9]++ ;
    	}
    	boolean [] prime = new boolean[n+1] ;
        int [] fac = new int [n+1] ;
        Arrays.fill(prime,true) ;
        Arrays.fill(fac,-1);
        for(int i=2; i*i<=n; i++)
        {
            if (prime[i])
            {
                for (int j=i*i; j<=n; j+=i)
                {
                	if(prime[j])
                	{
                		prime[j] = false;
                		fac[j] = i ;
                	}
                }
            }
        }
        for(int i = 2; i<=n ; i++)
        {
        	if(fac[i]==-1)
        	{
        		fac[i] = i ;
        	}
        }
        fac[1] =1 ;
    	long [] n_fac = new long[n+1] ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>() ;
    		int temp = i ;
    		while(temp!=1)
    		{
    			int p = fac[temp] ;
    			if(hm.containsKey(p))
    			{
    				hm.put(p,hm.get(p)+1) ;
    			}
    			else
    			{
    				hm.put(p,1) ;
    			}
//    			println(temp) ;
    			temp/=p ;
    		}
    		long ans = 1 ;
    		for(int p : hm.keySet())
    		{
    			ans = ans*(hm.get(p)+1) ;
    		}
    		n_fac[i] =ans ;
    	}
//    	println(10) ;
    	long ans = 0 ;
    	ArrayList<ArrayList<Pair>> ar = new ArrayList<ArrayList<Pair>>() ;
    	for(int i = 0 ; i<9 ; i++)
    	{
    		ar.add(new ArrayList<Pair>()) ;
    	}
    	for(int i = 0 ; i<9 ; i++)
    	{
    		for(int j = 0 ; j<9 ; j++)
    		{
    			for(int k = 0 ; k<9 ; k++)
    			{
    				if(j!=k)
    				{
    					if(((j%9)*(k%9))%9==i)
    					{
    						ar.get(i).add(new Pair(j,k)) ;
    					}
    				}
    			}
    		}
    		for(int j = 0 ; j<9 ; j++)
    		{
    			if((j*j)%9==i)
    			{
    				ar.get(i).add(new Pair(j,j)) ;
    			}
    		}
    	}
    	for(int i = 1 ; i<=n ; i++)
    	{
    		int m = i%9 ;
    		for(Pair p : ar.get(m))
    		{
    			ans+=ctr[p.get1()]*ctr[p.get2()] ;
    		}
    		ans-= n_fac[i] ;
    	}
    	println(ans) ;
    }
    static class Pair
    {
    	int v1 ;
    	int v2 ;
    	Pair(int a,int b)
    	{
    		v1 = a ;
    		v2 = b ;
    	}
    	public int get1()
    	{
    		return v1 ;
    	}
    	public int get2()
    	{
    		return v2 ;
    	}
    	@Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Pair)) return false;
            Pair key = (Pair) o;
            return v1 == key.v1 && v2 == key.v2;
        }
        @Override
        public int hashCode()
        {
            int result = v1;
            result = 37 * result + v2;
            return result;
        }

    }
}

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    private static class TaskB {

        static final long max = 1000000000000000000L;
        static final double eps = 0.0000001;
        static final long mod = 1000000007;
        static int N, M, K;
        static long X, Y;
        boolean V[][];
        int A[][], total;

        void solve(InputReader in, PrintWriter out) throws IOException {

            int N = in.nextInt();
            long res = 0;
            long[] D = new long[10];
            for (int i = 1; i <= N; ++i) {
                int sum = (i % 9 + 8) % 9 + 1;
                ++D[sum];
            }
            for (int A = 1; A < 10; ++A) {
                for (int B = 1; B < 10; ++B) {
                    int C = ((A * B) % 9 + 8) % 9 + 1;
                    res += D[A] * D[B] * D[C];
                }
            }

            for (int i = 1; i <= N; ++i) {
                res -= N / i;
            }

            out.println(res);
        }

        long gcd(long a, long b) {
            if (b == 0) return a;
            return gcd(b, a % b);
        }

        long lcm(long a, long b) {
            return (a * b) / gcd(a, b);
        }

        boolean isPrime(long n) {
            if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
                return false;
            for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)
                if (n % i == 0)
                    return false;
            return true;
        }

        double dist(double X1, double Y1, double X2, double Y2) {
            return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
        }

        boolean isEqual(double A, double B) {
            return Math.abs(A - B) < eps;
        }

        long extendEuc(long A, long B) {

            long lastX = 1, lastY = 0, temp;
            X = 0;
            Y = 1;

            while (B != 0) {
                long Q = A / B;
                long R = A % B;

                A = B;
                B = R;

                temp = X;
                X = lastX - Q * X;
                lastX = temp;

                temp = Y;
                Y = lastY - Q * Y;
                lastY = temp;
            }

            X = lastX;
            Y = lastY;

            return A;
        }
    }

    private static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public InputReader(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean ready() {
            try {
                return br.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

import java.io.Reader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Yakutov Dmitry
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastReader in = new FastReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, FastReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] cnt = new int[10];
        for (int i = 1; i <= 9; i++) {
            cnt[i] = (n + 9 - i) / 9;
        }
        long ans = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                ans += (long) cnt[i] * cnt[j] * cnt[(i * j - 1) % 9 + 1];
            }
        }
        for (int i = 1; i <= n; i++) {
            ans -= n / i;
        }
        out.println(ans);
    }
}

class FastReader extends BufferedReader {
    private StringTokenizer st;

    public FastReader(InputStream is) {
        super(new InputStreamReader(is));
    }

    public String nextToken() {
        try {
            while (st == null || !st.hasMoreElements()) {
                st = new StringTokenizer(readLine());
            }
            return st.nextToken();
        } catch (IOException e) {
            return null;
        }
    }

    public int nextInt() {
        return Integer.parseInt(nextToken());
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class C10
{
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is)
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }

    }

    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        long ans=0;
        int p[]=new int[n+1];
        for(int i=1;i<=n;i++)
            for(int j=i;j<=n;j+=i)
                p[j]++;
        long count[]=new long[10];
        for(int i=1;i<=n;i++)
        {
            int v=i;
            v%=9;
            if(v==0)
                v=9;
            count[v]++;
        }
        long dp[]=new long[10];
        for(int i=1;i<=9;i++)
        {
            for(int j=1;j<=9;j++)
            {
                int v=(i*j)%9;
                if(v==0)
                    v=9;
                dp[v]+=count[i]*count[j];
            }
        }
        for(int i=1;i<=n;i++)
        {
            int v=i;
            v%=9;
            if(v==0)
                v=9;
            ans+=dp[v]-p[i];
        }
        out.println(ans);
        out.close();
    }

}

import java.io.*;

/**
 * Created by James on 1/29/2015.
 */

public class Driver {
    public static void main(String [] args) throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(scanner.readLine().trim()), R = (int) Math.sqrt(N), sum = 0;

        for (int i = 1; i <= R; ++i) {
            sum += N / i;
        }

        sum = (sum * 2) - (int) Math.pow(R, 2);

        int [] digits = new int[10];

        for (int i = 1; i <= 9; ++i) {
            digits[i] = N / 9;
        }

        for (int i = 1; i <= N % 9; ++i) {
            digits[i]++;
        }

        long sum9s = 0;

        for (int i = 1; i <= 9; ++i) {
            if (digits[i] == 0) {
                continue;
            }

            for (int j = 1; j <= 9; ++j) {
                if (digits[i] == 0) {
                    continue;
                }

                int a = (i * j) % 9 == 0 ? 9 : (i * j) % 9;
                sum9s += (long) digits[i] * digits[j] * digits[a];
            }
        }

        out.println(sum9s - sum);
        out.close();
    }
}

//package codeforces;

import java.util.Scanner;

public class DigitalRoot {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        solve(in.nextInt());
    }

    private static void solve(int n) {
        long r = 0;
        for (int i = 1; i <= n; i++) {
            r += n / i;
        }

        long[] ct = new long[10];
        for (int i = 1; i <= 9; i++) {
            ct[i] = n / 9 + (i <= n % 9 ? 1 : 0);
        }

        long all = 0;
        for (int a = 1; a <= 9; a++) {
            for (int b = 1; b <= 9; b++) {
                all += ct[a] * ct[b] * ct[d(a * b)];
            }
        }
        System.out.println(all - r);
    }

    private static int d(int a) {
        int m = a % 9;
        return m == 0 ? 9 : m;
    }
}

import java.util.Scanner;

public class DigitalRoot {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        //we count the d for each number between 1 and n
        long[] count = new long[9];
        for (int i=1;i<=n;i++){
            count[i%9]++;
        }

        //we count all the combination possible according to Billy method
        long countAll=0;
        for(int a=0;a<9;a++){
            for(int b=0;b<9;b++){
                countAll+=count[a%9]*count[b%9]*count[a*b%9];
            }
        }

        //we remove the one who realy match;
        for(int i=1;i<=n;i++){
            countAll-=n/i;
        }

        System.out.println(countAll);

    }
}

//10C

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class DigitalRoot {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws IOException {

		int n = Integer.parseInt(br.readLine());

		/* Problem statement says (i*j == k) => (d(d(i)*d(j)) == d(k)) so we
		 * only need to check whether !(i*j == k) && (d(d(i)*d(j)) == d(k)).
		 * It's computationally cheaper to calculate A: how many times
		 * (d(d(i)*d(j)) == d(k)) is true and discount B: how many times
		 * (i*j == k) is true.
		 */
		System.out.println(A(n)-B(n));
	}

	private static int B(int n) {
		int sol = 0;
		for (int i = 1; i <= n; i++) {
			sol += n/i;
		}
		return sol;
	}

	private static long A(int n) {
		long[] cnt = new long[10];
		for (int i = 1; i < cnt.length; i++) {
			cnt[i] = (n+9-i)/9;
		}
		long sol = 0;
		for (int i = 1; i < cnt.length; i++) {
			for (int j = 1; j < cnt.length; j++) {
				for (int k = 1; k < cnt.length; k++) {
					if (i*j%9 == k%9) {
						sol += cnt[i]*cnt[j]*cnt[k];
					}
				}
			}
		}
		return sol;
	}
}

//10C

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		/* Problem statement says (i*j == k) => (d(d(i)*d(j)) == d(k)) so we
		 * only need to check whether !(i*j == k) && (d(d(i)*d(j)) == d(k)).
		 * It's computationally cheaper to calculate A: how many times
		 * (d(d(i)*d(j)) == d(k)) is true and discount B: how many times
		 * (i*j == k) is true.
		 */
		System.out.println(A(n)-B(n));
	}

	private static int B(int n) {
		int sol = 0;
		for (int i = 1; i <= n; i++) {
			sol += n/i;
		}
		return sol;
	}

	private static long A(int n) {
		long[] cnt = new long[10];
		for (int i = 1; i < cnt.length; i++) {
			cnt[i] = (n+9-i)/9;
		}
		long sol = 0;
		for (int i = 1; i < cnt.length; i++) {
			for (int j = 1; j < cnt.length; j++) {
				for (int k = 1; k < cnt.length; k++) {
					if (d(i*j) == d(k)) {
						sol += cnt[i]*cnt[j]*cnt[k];
					}
				}
			}
		}
		return sol;
	}

	public static int d(int n) {
		return (n-1)%9+1;
	}
}

import java.util.*;

public class cf10c {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] v = new long[10];
		for(int i=1; i<=n; i++) {
			int sum = i%9==0?9:i%9;
			v[sum]++;
		}
		long ret = 0;
		for(int i=1; i<10; i++) {
			for(int j=1; j<10; j++) {
				int x = (i*j)%9==0?9:(i*j)%9;
				ret += v[i]*v[j]*v[x];
			}
		}
		for(int i=1; i<=n; i++)
			ret -= n/i;
		System.out.println(ret);
	}
}

import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int MAXN = 1000000;

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int n = nextInt();
		int[] roots = new int [MAXN + 1];
		long[] withRoot = new long [10];
		for (int i = 1; i <= MAXN; i++) {
			roots[i] = getRoot(i);
			if (i <= n)
				withRoot[roots[i]]++;
		}
		long condCnt = 0;
		for (int i = 1; i < 10; i++)
			for (int j = 1; j < 10; j++)
				for (int k = 1; k < 10; k++)
					if (roots[i * j] == k) {
//						if (i == j && j == k) {
//							long t = withRoot[i];
//							condCnt += 2 * t * (t - 1) * (t - 2) / 6;
//						} else if (i == j && i != k)
//							condCnt += withRoot[i] * (withRoot[i] - 1) * withRoot[k];
//						else if (i == k && j != i)
//							condCnt +=
						condCnt += withRoot[i] * withRoot[j] * withRoot[k];
					}
		long notEqCnt = (long) n * n * n;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n / i; j++) {
				int mulRoot = roots[roots[i] * roots[j]];
				notEqCnt--;
			}
		long allCnt = (long) n * n * n;
//		System.out.println(notEqCnt);
//		System.out.println(condCnt);
		out.println(notEqCnt + condCnt - allCnt);
		in.close();
		out.close();
	}

	private int getRoot(int x) {
		int sum = 0;
		while (x > 0) {
			sum += x % 10;
			x /= 10;
		}
		if (sum < 10)
			return sum;
		return getRoot(sum);
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class c {

	int[] c;
	long[] cnt;
	int n;

	private void solve() throws Exception {
		n = nextInt();
		c = new int[n + 100];
		cnt = new long[10];
		for (int i = 1; i < 10; ++i){
			c[i] = i;
			if (i <= n)
				++cnt[i];
		}
		for (int i = 10; i <= Math.max(100, n); ++i){
			c[i] = c[c[i / 10] + (i % 10)];
			if (i <= n)
				++cnt[c[i]];
		}
		long goodCnt = getGood(n);
		long badCnt = 0;
		//out.println(goodCnt);
		for (int a = 1; a < 10; ++a)
			for (int b = 1; b < 10; ++b)
				badCnt += cnt[a] * cnt[b] * cnt[c[a * b]];
		out.print(badCnt - goodCnt);
	}

	private long getGood(int n) {
		long ans = 0;
		for (int i = 1; i <= n; ++i)
			ans += n / i;
		return ans;
	}

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			NOO(e);
		} finally {
			out.close();
		}
	}

	PrintWriter out;
	BufferedReader in;
	StringTokenizer St;

	void NOO(Exception e) {
		e.printStackTrace();
		System.exit(1);
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	String nextToken() {
		while (!St.hasMoreTokens()) {
			try {
				String line = in.readLine();
				St = new StringTokenizer(line);
			} catch (Exception e) {
				NOO(e);
			}
		}
		return St.nextToken();
	}

	private c(String name) {
		try {
			in = new BufferedReader(new FileReader(name + ".in"));
			St = new StringTokenizer("");
			out = new PrintWriter(new FileWriter(name + ".out"));
		} catch (Exception e) {
			NOO(e);
		}
	}

	private c() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			St = new StringTokenizer("");
			out = new PrintWriter(System.out);
		} catch (Exception e) {
			NOO(e);
		}
	}

	public static void main(String[] args) {
		new c().run();
	}

}

import java.io.*;
import java.util.*;
public class C10 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		long[] go = gen(n);
		long ret = 0;
		for(int a = 1; a <= n; a++)	{
			int b = n/a;
			long[] next = gen(b);
			for(int i = 0; i < 9; i++)	{
				ret += (go[((a%9)*(i%9))%9]-1) * next[i%9];
				ret += (go[((a%9)*(i%9))%9]) * (go[i%9] - next[i%9]);
			}
		}
		System.out.println(ret);
	}
	public static long[] gen(int x)	{
		long[] ret = new long[9];
		Arrays.fill(ret, x/9);
		for(int i = 1; i <= x%9; i++)
			ret[i]++;
		return ret;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {
    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    void solve() throws IOException {
        int n = nextInt();
        int countTrue = 0;
        for (int a = 1; a <= n; ++a) {
            countTrue += n / a;
        }

        int[] cnt = new int[9];
        for (int i = 1; i <= n; ++i) {
            ++cnt[i % 9];
        }
        long answer = 0;
        for (int i = 0; i < 9; ++i) {
            for (int j = 0; j < 9; ++j) {
                answer += (long)cnt[i] * (long)cnt[j] * (long)cnt[(i * j) % 9];
            }
        }
        out.println(answer - countTrue);
    }

    public void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        eat("");
        solve();
        out.close();
        in.close();
    }

    void eat(String s) {
        st = new StringTokenizer(s);
    }

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            eat(line);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static void main(String[] args) throws IOException {
        new C().run();
    }
}

import java.util.*;

public class LRBS {

    static int sum(int n){
        int y =0;

        while(n!=0){
            y+= (n%10);
            n = n/10;
        }
        return y;
    }
    public static  void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int a[] = new int[1000001];

        for(int i=1;i<10;i++){
            a[i] = i;
        }

        for(int i=10;i<a.length;i++){
            a[i] = a[sum(i)];
        }

         long digit[]=  new long[10];

        for(int i=1;i<=n;i++){
            digit[a[i]]++;
        }

        long res = 0;
        for(int i=1;i<=9&&i<=n;i++){
            for(int j=1;j<=9&&j<=n;j++){

                     res += digit[i]*digit[j]*digit[a[i*j]];

            }
        }
        for(int i=1;i<=n;i++){
            res -= (n/i);
        }

        System.out.println(res);
    }
}

import java.util.*;

public class CF10C {
	public static void main(String[] args) {
		int n = new Scanner(System.in).nextInt();
		int r = (int) Math.sqrt(n);
		int sum = 0;
		for (int i = 1; i <= r; i++)
			sum += n / i;
		sum *= 2;
		sum -= r * r;
		int[] aa = new int[10];
		for (int i = 1; i <= 9; i++)
			aa[i] = n / 9;
		for (int i = 1; i <= n % 9; i++)
			aa[i]++;
		long sum9 = 0;
		for (int i = 1; i <= 9; i++)
			for (int j = 1; j <= 9; j++) {
				int k = i * j % 9;
				if (k == 0)
					k = 9;
				sum9 += (long) aa[i] * aa[j] * aa[k];
			}
		System.out.println(sum9 - sum);
	}
}

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
//        InputStream inputStream = new FileInputStream("sum.in");
        OutputStream outputStream = System.out;
//        OutputStream outputStream = new FileOutputStream("sum.out");

//        Path path = Paths.get(URI.create("file:///foo/bar/Main.java"));
//        System.out.print(path.getName(200));

//        Path p = Paths.get("/foo/bar/Main.java");
//        for (Path e : p) {
//            System.out.println(e);
//        }

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Answer solver = new Answer();
        solver.solve(in, out);
        out.close();
    }
}

class Answer {
    private final int INF = (int) (1e9 + 7);
    private final int MOD = (int) (1e9 + 7);
    private final int MOD1 = (int) (1e6 + 3);
    private final long INF_LONG = (long) (1e18 + 1);
    private final double EPS = 1e-9;

    public void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();

        int[][] a = new int[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                a[i][j] = (i * j) % 9;
            }
        }

        int[] b = new int[9];
        for (int i = 1; i <= n; i++) {
            b[i % 9]++;
        }

        long x = 0;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                x += 1L * b[i] * b[j] * b[a[i][j]];
            }
        }

        long y = 0;
        for (int i = 1; i <= n; i++) {
            y += n / i;
        }

        out.print(x - y);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ProblemC {
	public static void main(String[] args) throws IOException {
		InputStream in = System.in;
		InputReader scan = new InputReader(in);
		long count = 0L;
		int n = scan.nextInt();
		int[] modDiff = new int[10];
		for(int i=1;i<=n;i++) {
			int digiI = digitalRoot(i);
			modDiff[digiI]++;
		}
		//Counting all d(a*b) = d(d(a)*d(b)) => d(c) = d(d(a)*d(b))
		//This count also includes c = a*b
		for(int a=1;a<10;a++) {
			for(int b=1;b<10;b++) {
				int c = digitalRoot(a*b);
				count += (long) modDiff[a] * modDiff[b] * modDiff[c];
			}
		}
		//Excluding c = a*b
		for(int i=1;i<=n;i++) {
			count -= n/i;
		}
		System.out.println(count);
	}
	static int digitalRoot(int n) {
		return ((n-1)%9)+1;
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public float nextFloat() {
			return Float.parseFloat(next());
		}

		/**
		 ** Use when you are sure input will be single character
		 */
		public char nextChar() {
			return next().charAt(0);
		}
	}
}

import java.util.Scanner;

public class C10 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            int j = 1;
            while (i*j <= n) {
                ans--;
                j++;
            }
        }
        int[]d = new int[10];
        for (int i = 1; i <= n; i++) {
            d[digroot(i)]++;
        }
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                for (int j2 = 1; j2 <= 9; j2++) {
                    if (digroot(j*j2)==i) {
                        ans += (long)d[i]*d[j]*d[j2];
                    }
                }
            }
        }
        System.out.println(ans);
    }

    private static int digroot(int n) {
        int s = 0;
        while (n > 0) {
            s += n % 10;
            n /= 10;
        }
        if (s <= 9)
            return s;
        return digroot(s);
    }
}

import java.io.File;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;

public class CodeforcesA
{

    /**
     * @param args
     */
    Scanner inp;
    PrintWriter out;

    void run() throws Exception
    {
        inp = new Scanner(System.in);
        out = new PrintWriter(System.out);

        int n = inp.nextInt();

        int[] count = new int[n+1];
        for (int i = 1; i <= 1000; i++)
            for (int j = i; j <= n; j += i)
                if (i*i < j) count[j] +=2;
                else if (i*i == j) count[j] ++;

        long[] root = new long[9];
        for (int i = 1; i <= n; i++) root[i%9]++;

        long ans = 0;
        for (int c = 1; c <= n; c++)
        {
            int real = count[c];
            int cop = c % 9;

            long fake = 0;
            for (int i = 0; i < 9 ;i++)
                for (int j = 0; j < 9; j++)
                    if ((i*j)%9 == cop)
                        fake += root[i] * root[j];
            fake -= real;
            ans += fake;

        }

        out.print(ans);

        out.close();
        inp.close();

    }

    public static void main(String[] args) throws Exception
    {
        // TODO Auto-generated method stub
        new CodeforcesA().run();

    }

}

import java.util.Scanner;

public class CF10C {
	private static int[] cnt(int n) {
		int[] res = new int[9];
		for (int i = 0; i < 9; i++) {
			res[i] = n / 9 + (n % 9 >= i && i != 0 ? 1 : 0);
		}
		return res;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long res = 0;
		for (int i = 1; i <= n; i++) {
			int[] cnt = cnt(n / i);
			int[] cnt_n = cnt(n);
			for (int j = 0; j < 9; j++) {
				res += (long) cnt[j] * (cnt_n[(i * j) % 9] - 1);
				res += (long) (cnt_n[j] - cnt[j]) * cnt_n[(i * j) % 9];
			}
		}
		System.out.println(res);
		sc.close();
	}
}

import java.io.*;
import java.util.*;

public class Task {
    public static int n,p1,p2,p3,t1,t2,energy;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        long s = 0;
        long[] c = new long[10];
        for(int i=1;i<n+1;i++){
            s-= n/i;
            c[ i % 9 ] = c[ i % 9 ] + 1;
        }

        for(int i=0;i<9;i++)
            for(int j=0;j<9;j++){
                s+= c[i] * c[j] * c[ i * j % 9 ];
            }

        System.out.print(s);

    }

}

//"Pure violence will become the only basis of power" - :)
import java.util.*;
import java.io.*;

public class Solution {
	public static PrintWriter w = new PrintWriter(System.out);
	public static void main(String args[] ) throws Exception {
		Reader in = new Reader();
		int t = 1;//in.nextInt();
		while(t-- > 0) {
			int n = in.nextInt();
			int[] dr = new int[10];
			for (int i=1; i<=n; i++)
				dr[(i%9 != 0) ? i%9 : 9]++;
			long ans = 0;
			for (int i=1; i<10; i++) {
				for (int j=1; j<10; j++) {
					int c = (i*j)%9  != 0 ? (i*j)%9 : 9;
					ans += (long)dr[i]*dr[j]*dr[c];
				}
			}
			for (int i=1; i<=n; i++)
				ans -= n/i;
			w.println(ans);
		}
		w.flush();
		return;
	}
}

class Reader {
	final private int BUFFER_SIZE = 1 << 16;
	private DataInputStream din;
	private byte[] buffer;
	private int bufferPointer, bytesRead;

	public Reader() {
		din = new DataInputStream(System.in);
		buffer = new byte[BUFFER_SIZE];
		bufferPointer = bytesRead = 0;
	}
	public String nextLine() throws IOException {
		int c = read();
		while(isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while(!isEndOfLine(c));
		return res.toString();
	}
	public String next() throws IOException {
		int c = read();
		while(isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while(!isSpaceChar(c));
		return res.toString();
	}
	public int nextInt() throws IOException {
		int ret = 0;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}
	public int[] nextIntArray(int n) throws IOException {
		int a[] = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}
	public int[][] next2dIntArray(int n, int m) throws IOException {
		int a[][] = new int[n][m];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				a[i][j] = nextInt();
		return a;
	}
	public char nextChar() throws IOException {
		return next().charAt(0);
	}
	public long nextLong() throws IOException {
		long ret = 0;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}
	public double nextDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (c == '.') {
			while((c = read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}
		if(neg)
			return -ret;
		return ret;
	}
	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if(bytesRead == -1)
			buffer[0] = -1;
	}
	private byte read() throws IOException {
		if(bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}
	public void close() throws IOException {
		if(din == null)
			return;
		din.close();
	}
	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
	private boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}
}

import java.io.*;
import java.util.*;
public class C10 {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	long n = input.nextInt();
	long res = 0;
	for(int i = 1; i<=9; i++)
		for(int j = 1; j<=9; j++)
		{
			int prod = (i*j)%9;
			if(prod == 0) prod = 9;
			res += ((n+9-i)/9) * ((n+9-j)/9) * ((n+9-prod)/9);
		}
	for(int i = 1; i<=n; i++)
	{
		res -= n/i;
	}
	out.println(res);
	out.close();
}

public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
	reader = new BufferedReader(new InputStreamReader(input));
	tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
	while (!tokenizer.hasMoreTokens())
		tokenizer = new StringTokenizer(reader.readLine());
	return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
	return Integer.parseInt(next());
	}

	static double nextDouble() throws IOException {
	return Double.parseDouble(next());
	}

	static long nextLong() throws IOException {
	return Long.parseLong(next());
	}
}
}

import java.io.*;
import java.util.*;
public class C10 {
public static void main(String[] args) throws IOException {
    input.init(System.in);
    PrintWriter out = new PrintWriter(System.out);
    long n = input.nextInt();
    long res = 0;
    for(int i = 1; i<=9; i++)
        for(int j = 1; j<=9; j++)
        {
            int prod = (i*j)%9;
            if(prod == 0) prod = 9;
            res += ((n+9-i)/9) * ((n+9-j)/9) * ((n+9-prod)/9);
        }
    for(int i = 1; i<=n; i++)
    {
        res -= n/i;
    }
    out.println(res);
    out.close();
}

public static class input {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
    reader = new BufferedReader(new InputStreamReader(input));
    tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
    while (!tokenizer.hasMoreTokens())
        tokenizer = new StringTokenizer(reader.readLine());
    return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
    return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
    return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
    return Long.parseLong(next());
    }
}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot
{

	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(in.readLine());
		long [] Nd = new long[10];
		for (int i = 1; i<=N%9; ++i)
		{
			Nd[i] = N/9 + 1;
		}
		for(int i = N%9+1; i<10; ++i)
		{
			Nd[i] = N/9;
		}
		long t = 0;
		for(int d1 = 1; d1 < 10; ++d1)
			for(int d2 = 1; d2 < 10; ++d2)
				t+=Nd[d1]*Nd[d2]*Nd[digitalRoot(d1*d2)];
		for(int x = 1; x <= N; ++x)
		{
			t-= N/x;
		}
		System.out.println(t);
	}

	public static int digitalRoot(int n)
	{
		return ((n-1)%9)+1;
	}

}

import java.util.*;
public class Digital {
public static void main(String [] args){
Scanner in=new Scanner(System.in);
long n=in.nextLong();
long array[]=new long[10];
int a=(int)n%9;
for(int i=1;i<=9;i++){
array[i]=n/9;
}
for(int i=1;i<=n%9;i++){
array[i]++;
}
long ans=0;
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
int temp=(int)i*j%9;
if(temp==0)
temp=9;
ans+=array[i]*array[j]*array[temp];
}
}
for(int i=1;i<=n;i++){
ans-=n/i;
}
System.out.println(ans);
}
}

import java.lang.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
          long good = 0;
          int sqn = (int) (Math.sqrt(n) + 2);
          for (int a = 1; a <= sqn; ++a) {
            for (int b = a; b*a <= n; ++b) {
              if (a == b) good++;
              else good += 2;
            }
          }
        //  printf("good %lld\n", good);
          int[] kcnt = new int[10];
          int[] dkor = new int[1000100];
          for (int i = 1; i <= 1000000; ++i) {
            if (i <= 9)
              dkor[i] = i;
            else {
              int sum = 0;
              int t = i;
              while (t != 0) {
                sum += t % 10;
                t /= 10;
              }
              dkor[i] = dkor[sum];
//            printf("deb %d %d %d\n", i, dkor[i], sum);
            }
          }

          for (int i = 1; i <= n; ++i) {
            kcnt[dkor[i]] += 1;
          }
        //  for (int i = 1; i < 10; ++i)
//          printf("%d ", kcnt[i]);
        //  printf("\n");
          BigInteger bad = BigInteger.ZERO;
          for (int a = 1; a <= 9; ++a) {
            for (int b = 1; b <= 9; ++b) {
              int dc = dkor[a * b];
                //if (a != b && a != dc && b != dc) {
                  bad = bad.add(BigInteger.valueOf(kcnt[a]).multiply(BigInteger.valueOf(kcnt[b]).multiply(BigInteger.valueOf(kcnt[dc]))));
                /*} else if ( a == b && a == dc) {
                  bad += kcnt[a] * (kcnt[a] - 1) * (kcnt[a] - 2);
                } else if ( a == b) {
                  bad += kcnt[a] * (kcnt[a] - 1) * kcnt[dc];
                } else if (a == dc) {
                  bad += kcnt[a] * (kcnt[a] - 1) * kcnt[b];
                } else if (b == dc) {
                  bad += kcnt[b] * (kcnt[b] - 1) * kcnt[a];
                } else {
                  printf("EPIC!\n");
                  return 0;
                }*/
                //printf("%d %d %d %lld\n", a,b,dc,bad);
            }
          }
          System.out.println(bad.subtract(BigInteger.valueOf(good)));

    }
}

/*
import java.io.*;
import java.util.*;
import c08.*; // Contains StrSortVector

class Counter {
  private int i = 1;
  int read() { return i; }
  void increment() { i++; }
}

public class SortedWordCount {
  private FileInputStream file;
  private StreamTokenizer st;
  private Hashtable counts = new Hashtable();
  SortedWordCount(String filename)
    throws FileNotFoundException {
    try {
      file = new FileInputStream(filename);
      st = new StreamTokenizer(file);
      st.ordinaryChar('.');
      st.ordinaryChar('-');
    } catch(FileNotFoundException e) {
      System.out.println(
        "Could not open " + filename);
      throw e;
    }
  }
  void cleanup() {
    try {
      file.close();
    } catch(IOException e) {
      System.out.println(
        "file.close() unsuccessful");
    }
  }
  void countWords() {
    try {
      while(st.nextToken() !=
        StreamTokenizer.TT_EOF) {
        String s;
        switch(st.ttype) {
          case StreamTokenizer.TT_EOL:
            s = new String("EOL");
            break;
          case StreamTokenizer.TT_NUMBER:
            s = Double.toString(st.nval);
            break;
          case StreamTokenizer.TT_WORD:
            s = st.sval; // Already a String
            break;
          default: // single character in ttype
            s = String.valueOf((char)st.ttype);
        }
        if(counts.containsKey(s))
          ((Counter)counts.get(s)).increment();
        else
          counts.put(s, new Counter());
      }
    } catch(IOException e) {
      System.out.println(
        "st.nextToken() unsuccessful");
    }
  }
  Enumeration values() {
    return counts.elements();
  }
  Enumeration keys() { return counts.keys(); }
  Counter getCounter(String s) {
    return (Counter)counts.get(s);
  }
  Enumeration sortedKeys() {
    Enumeration e = counts.keys();
    StrSortVector sv = new StrSortVector();
    while(e.hasMoreElements())
      sv.addElement((String)e.nextElement());
    // This call forces a sort:
    return sv.elements();
  }
  public static void main(String[] args) {
    try {
      SortedWordCount wc =
        new SortedWordCount(args[0]);
      wc.countWords();
      Enumeration keys = wc.sortedKeys();
      while(keys.hasMoreElements()) {
        String key = (String)keys.nextElement();
        System.out.println(key + ": "
                 + wc.getCounter(key).read());
      }
      wc.cleanup();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
} ///:~
*/

import java.io.*;
import java.util.*;
import java.math.*;
public class DigitRoot {
	int n;

	public static void main(String [] args) {
		new DigitRoot().solve();
	}

	private void solve() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int [] root = new int[10000001];
		int [] repeat = new int[10];
		for(int i = 1; i<=Math.max(n, 81); ++i) {
			root[i] = d(i);
		}
		for(int c = 1; c<=n; ++c) {
			++repeat[root[c]];
		}
		long ans = 0;
		for(int i = 1; i<=Math.min(n, 9); i++) {
			for(int j = 1; j<=Math.min(n, 9); j++) {
				for(int k = 1; k<=Math.min(n, 9); k++) {
					if(root[k*j] == root[i]) {
						ans += (long)repeat[i] * (long)repeat[j] * (long)repeat[k];
					}
				}
			}
		}
		long abc = 0, valid=0;
		for(int i = 1; i<=n; i++) {
			int k = n/i;

			for(int j = 1; j<=k; j++) {
				++abc;

				if(root[i*j] == root[root[i]*root[j]]){
					++valid;
				}
			}
		}
		System.out.println(abc+ans-2*valid);

	}
	private int d(int x) {
		int res = 0;
		while(x>0) {
			res+=x%10;
			x /= 10;
		}
		if(res>=10) return d(res);
		return res;
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		 // cantidad[i]: el numero de numeros x en [1,n] que d(x) = i
        int[] cantidad = new int[10];
        for (int i = 1; i <=n; i++){
        	int root = dr(i);
        	cantidad[root]+=1;
        }

        long resultado = 0;

        // Contar todas las tuplas (i,j,k) tal que d(d(i)*d(j))=d(k)
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++)
                resultado += (long)cantidad[i] * cantidad[j] * cantidad[dr(i*j)];
        }

        // Por cada i, hay  n/i tuplas (i,j,k) donde j = 1, ..., n/i tal que i*j = k.
        // Remover estos desde resultado, y lo restante es el numero de tuplas
        //  tal que el algoritmo falla.

        for (int i = 1; i <= n; i++)
            resultado -= n / i;

        System.out.println(resultado);
	}

	public static int dr(int n) {
		return 1 + ((n - 1) % 9);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		 // cantidad[i]: el numero de numeros x en [1,n] que d(x) = i
        int[] cantidad = new int[10];
        for (int i = 1; i <=n; i++){
        	int root = dr(i);
        	cantidad[root]+=1;
        }

        long resultado = 0;

        // Contar todas las tuplas (i,j,k) tal que d(d(i)*d(j))=d(k)
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++)
                resultado += (long)cantidad[i] * cantidad[j] * cantidad[(i*j-1)%9+1];
        }

        // Por cada i, hay  n/i tuplas (i,j,k) donde j = 1, ..., n/i tal que i*j = k.
        // Remover estos desde resultado, y lo restante es el numero de tuplas
        //  tal que el algoritmo falla.

        for (int i = 1; i <= n; i++)
            resultado -= n / i;

        System.out.println(resultado);
	}

	public static int dr(int n) {
		return 1 + ((n - 1) % 9);
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws FileNotFoundException, IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();

	}
}

class Circles {
	Pair point;
	double second;

	Circles(Pair point, double second) {
		this.point = point;
		this.second = second;
	}
}

class Pair {
	double first;
	double second;

	Pair(double first, double second) {
		this.first = first;
		this.second = second;
	}

}

// pair problem can be done using stack
class TaskB {
	int MAXN = (int) 1e9 + 7;
	double t1;
	double t2;
	double eps = 1e-10;
	double d[];

	void solve(int testNumber, InputReader in, PrintWriter pw) {
		int n = in.nextInt();
		int div[] = new int[n + 1];
		for (int i = 1; i <= n; ++i) {
			for (int j = i; j <= n; j += i) {
				div[j]++;
			}
		}
		int cnt[] = new int[10];
		long dig[] = new long[n + 1];
		for (int i = 1; i <= n; ++i) {
			int d_sum = 0;
			int num = i;
			while (num > 0) {
				int d = num % 10;
				d_sum = (d_sum + d);
				if (d_sum > 9) {
					d_sum -= 9;
				}
				num /= 10;
			}
			cnt[d_sum]++;
			dig[i] = (div[i]) * 1L * (div[i] - 1);
		}
		long ans = 0;
		for (int j = 0; j < 10; ++j) {
			for (int k = 0; k < 10; ++k) {
				int prod = j * k;
				int num1 = prod % 10;
				num1 += prod / 10;
				if (num1 > 9) {
					num1 -= 9;
				}
				ans += (cnt[j] * 1L * cnt[k] * 1L * cnt[num1]);
			}
		}
		for (int i = 1; i <= n; ++i) {
			ans -= n / i;
		}
		pw.println(ans);
	}

	long pow(int n, int m) {
		if (m == 0)
			return 1;
		long ans = pow(n, m / 2);
		ans = (ans * ans);
		if (m % 2 == 1) {
			ans = (ans * n);
		}
		return ans;
	}

	double pow(double n, int m) {
		if (m == 0)
			return 1;
		double ans = pow(n, m / 2);
		ans = (ans * ans);
		if (m % 2 == 1) {
			ans = (ans * n);
		}
		return ans;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

import java.io.PrintWriter;
import java.util.Scanner;
import java.util.stream.IntStream;

public class C {

    public void run(Scanner in, PrintWriter out) {
        int N = in.nextInt();
        long res = 0;
        for (int i = 1; i <= N; i++) {
            res -= N / i;
        }
        for (int i = 1; i <= 9; i++) {
            long as = (N + 9 - i) / 9;
            for (int j = 1; j <= 9; j++) {
                long bs = (N + 9 - j) / 9;
                int k = (i * j) % 9;
                if (k == 0) k = 9;
                long cs = (N + 9 - k) / 9;
                res += as * bs * cs;
            }
        }
        out.println(res);
    }

    public static void main(String[] args) {
        try (
                Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out);
        ) {
            new C().run(in, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

import java.io.*;
import java.util.*;

public class T10C {
    int d(int x) {
        int result = 0;

        while (x > 0) {
            result += x % 10;
            x /= 10;
        }

        if (result <= 9) {
            return result;
        } else {
            return d(result);
        }
    }

    void solve() throws IOException {
        int n = nextInt();

        long[] counts = new long[10];
        for (int i = 1; i <= n; ++i) {
            counts[d(i)]++;
        }

        long result = 0;
        for (int i = 1; i <= 9; ++i) {
            for (int j = 1; j <= 9; ++j) {
                int k = d(i * j);

                result += counts[i] * counts[j] * counts[k];
            }
        }

        for (int i = 1; i * i <= n; ++i) {
            for (int j = i; i * j <= n; ++j) {
                result--;

                if (i != j) {
                    result--;
                }
            }
        }

        out.println(result);
    }

    void run() throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        // reader = new BufferedReader(new FileReader("file.in"));
        // out = new PrintWriter(new FileWriter("file.out"));
        tokenizer = null;
        solve();
        reader.close();
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new T10C().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}

import java.io.*;
import java.util.*;

/**
 * BEGIN NO SAD
 * Blessed are those who suffer for doing what is right.
 * The kingdom of heaven belongs to them.
 * (Matthew 5:10-12)
 * @author Tran Anh Tai
 * @template for CP codes
 * END NO SAD
 */
public class ProbC {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task{
        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long divs = 0;
            int sqrt = (int)(Math.sqrt(n));
            for (int i = 1; i <= n; i++){
                divs += (n / i);
            }
            int cnt[] = new int[10];
            for (int d = 1; d <= 9; d++){
                if (n < d){
                    cnt[d] = 0;
                }
                else {
                    cnt[d] = (n - d) / 9 + 1;
                }
            }
            long total = 0;
            for (int da = 1; da <= 9; da++){
                for (int db = 1; db <= 9; db++){
                    int dc = (da * db) % 9;
                    if (dc == 0) dc = 9;
                    total += (long)cnt[da] * cnt[db] * cnt[dc];
                }
            }
            out.println(total - divs);
        }
    }

    static class Edge{
        public int dest, weight;
        public Edge(int dest, int weight){
            this.dest = dest; this.weight = weight;
        }
    }
    static class Pair{
        public int x, y;
        public Pair(int x, int y){
            this.x = x;
            this.y = y;
        }
    }
    static class Point{
        public double x, y;
        public Point(double x, double y){
            this.x = x; this.y = y;
        }
        public static Line getBisect(Point A, Point B){
            double a = B.x - A.x;
            double b = B.y - A.y;
            double c = a * (A.x + B.x) / 2 + b * (A.y + B.y) / 2;
            return new Line(a, b, c);
        }
        public static Point center(Point A, Point B, Point C){
            Line lab = getBisect(A, B);
            Line lac = getBisect(A, C);
            Point intersect = Line.intersect(lab, lac);
            return intersect;
        }
    }
    static class Line{
        public double a, b, c;
        public Line(double a, double b, double c){
            this.a = a; this.b = b; this.c = c;
        }
        public static Point intersect(Line l1, Line l2){
            double D = l1.a * l2.b - l1.b * l2.a;
            double Dy = l1.a * l2.c - l2.a * l1.c;
            double Dx = l1.c * l2.b - l2.c * l1.b;
            return new Point(Dx / D, Dy / D);
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}

import java.util.Scanner;

public class DigitalRoot {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int digits[] = new int[9];
		long result = 0;
		for (int i = 1; i <= n; i++) {
			digits[i%9]++;
			result -= (n/i);
		}
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				result += 1L*digits[i]*digits[j]*digits[(i*j)%9];
			}
		}
		System.out.println(result);
	}

}

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();

            int s = 0;
            for (int i = 1; i <= n; i++) {
                s += n/i;
            }

            long t = -s;
            for (int i = 1; i <= Math.min(n, 9); i++) {
                long ti = 0;
                for (int j = 1; j <= Math.min(n, 9); j++) {
                    for (int k = 1; k <= n; k++) {
                        if ((i*j)%9 == k%9) {
                            ti += n/9;
                            if (n%9 >= j) ti++;
                        }
                    }
                }
                t += (n/9)*ti;
                if (n%9 >= i) t += ti;
            }

//            int tr = 0;
//            for (int i = 1; i <= n; i++) {
//                for (int j = 1; j <= n; j++) {
//                    for (int k = 1; k <= n; k++) {
//                        if ((i*j)%9 == k%9) tr++;
//                    }
//                }
//            }

            System.out.println(t);
        }
    }
}
// 53435215015075583

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();

            int s = 0;
            for (int i = 1; i <= n; i++) {
                s += n/i;
            }

            BigInteger t = BigInteger.ZERO;
            for (int i = 1; i <= Math.min(n, 9); i++) {
                long ti = 0;
                for (int j = 1; j <= Math.min(n, 9); j++) {
                    for (int k = 1; k <= n; k++) {
                        if ((i*j)%9 == k%9) {
                            ti += n/9;
                            if (n%9 >= j) ti++;
                        }
                    }
                }
                t = t.add(BigInteger.valueOf((n/9)*ti));
                if (n%9 >= i) t = t.add(BigInteger.valueOf(ti));
            }

//            int tr = 0;
//            for (int i = 1; i <= n; i++) {
//                for (int j = 1; j <= n; j++) {
//                    for (int k = 1; k <= n; k++) {
//                        if ((i*j)%9 == k%9) tr++;
//                    }
//                }
//            }

            System.out.println(t.subtract(BigInteger.valueOf(s)));
        }
    }
}

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class _P010C{
    Scanner sc=new Scanner(System.in);

    int INF=1<<28;
    double EPS=1e-9;

    int n;

    void run(){
        n=sc.nextInt();
        solve();
    }

    void solve(){
        int[] d=new int[max(n+1, 100)];
        long[] count1=new long[10];
        long[] count2=new long[10];
        for(int i=1; i<d.length; i++){
            int sum=0;
            for(int j=i; j>0; j/=10){
                sum+=j%10;
            }
            if(sum<10){
                d[i]=sum;
            }else{
                d[i]=d[sum];
            }
            if(i<=n){
                count1[d[i]]++;
            }
        }
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                count2[d[i*j]]+=count1[i]*count1[j];
            }
        }
        // debug(d);
        // debug(count1);
        // debug(count2);

        // debug("here");

        boolean[] isPrime=new boolean[n+1];
        int[] nDivisor=new int[n+1];
        fill(isPrime, true);
        isPrime[0]=isPrime[1]=false;
        for(int j=0; j<=n; j++){
            if(isPrime[j]){
                // nDivisor[j]+=2;
                for(int i=j*2; i<=n; i+=j){
                    isPrime[i]=false;
                    int k;
                    for(k=i; k%j==0; k/=j){
                        nDivisor[i]++;
                    }
                    if(k==1){
                        nDivisor[i]--;
                    }
                }
            }
        }
        // debug(nDivisor);

        long ans=0;
        for(int i=1; i<=n; i++){
            ans+=count2[d[i]];
            ans-=n/i;
        }
        println(""+ans);
    }

    int nDivisor(int n){
        if(BigInteger.valueOf(n).isProbablePrime(200)){
            return 2;
        }
        int res=0;
        for(int i=1; i*i<=n; i++){
            if(n%i==0){
                res++;
                if(n/i!=i){
                    res++;
                }
            }
        }
        return res;
    }

    void println(String s){
        System.out.println(s);
    }

    void print(String s){
        System.out.print(s);
    }

    void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args){
        new _P010C().run();
    }
}

import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Date: 19.02.2010
 * Time: 14:56:28
 *
 * @author Sergey Bankevich (Sergey.Bankevich@gmail.com)
 */
public class C10 {
    static Scanner in;

    public static void main( String[] args ) throws FileNotFoundException {
        in = new Scanner( System.in );
        int n = in.nextInt();
        long res = 0;
        long[] a = new long[10];
        for ( int i = 1; i <= 9; i ++ ) {
            a[i] = ( n - i + 9 ) / 9;
        }
        for ( int i = 1; i <= 9; i ++ ) {
            for ( int j = 1; j <= 9; j ++ ) {
                int k = ( i * j ) % 9;
                if ( k == 0 ) {
                    k = 9;
                }
                res += a[i] * a[j] * a[k];
            }
        }
        long j = n;
        for ( long i = 1; i <= n; i ++ ) {
            while ( i * j > n ) {
                j --;
            }
            res -= j;
        }
        System.out.println( res );
    }
}

import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		long sumDivs = 0;
		long[] dr = new long[9];
		for (int i = 1; i <= n; ++i) {
			sumDivs += n / i;
			dr[i % 9]++;
		}
		long ans = 0;
		for (int i = 0; i < 9; ++i) {
			for (int j = 0; j < 9; ++j) {
				ans += dr[i] * dr[j] * dr[(i * j) % 9];
			}
		}
		ans -= sumDivs;
		out.println(ans);
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class C10 {

	static StreamTokenizer in;
	static PrintWriter out;

	static int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}

	static String nextString() throws IOException {
		in.nextToken();
		return in.sval;
	}

	public static void main(String[] args) throws IOException {
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out = new PrintWriter(System.out);

		int n = nextInt();
		long ans = 0;

		/*for (int a = 1; a <= n; a++)
			for (int b = 1; b <= n; b++)
				for (int c = 1; c <= n; c++)
					if (a*b%9 == c%9 && a*b != c) ans++;

		out.println(ans);
		ans = 0;

		for (int a = 1; a <= n; a++) {
			int[] r = new int[9];
			for (int b = 1; b <= n; b++) {
				int x = a*b%9;
				r[x]++;
				if (x == 0) x = 9;
				ans += (n-x+9)/9;
				if (a*b <= n) ans--;
			}
			//out.print(a + ": ");
			//for (int i = 0; i < 9; i++) out.print(r[i] + " ");
			//out.println();
		}

		out.println(ans);
		ans = 0;*/

		int[][] m = new int[9][9];
		for (int i = 0; i < 9; i++)
			for (int j = 0; j < 9; j++)
				m[i][j] = i*j%9;

		long[] cnt = new long[9];
		for (int i = 1; i <= n; i++) cnt[i%9]++;

		for (int a = 1; a <= n; a++) {
			ans -= n/a;
			int x = a%9;
			long[] r = new long[9];
			for (int i = 0; i < 9; i++) r[m[x][i]] += cnt[i];
			for (int i = 0; i < 9; i++) ans += (n-(i == 0 ? 9 : i)+9)/9*r[i];
			//out.print(a + ": ");
			//for (int i = 0; i < 9; i++) out.print(r[i] + " ");
			//out.println();
		}

		out.println(ans);

		out.flush();
	}

}

import java.io.*;
import java.math.*;
import java.util.*;

public class C {
	public static void main(String[] args) {
		new C().run();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		boolean eof;
		String buf;

		public FastScanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
			nextToken();
		}

		public FastScanner(InputStream stream) {
			br = new BufferedReader(new InputStreamReader(stream));
			nextToken();
		}

		String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		void close() {
			try {
				br.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	void solve() {
		long n = nextLong();
		long cur = n;
		long ans = 0;
		for (long i = 1; i <= n; i++) {
			while (i * cur > n) {
				--cur;
			}
			ans -= cur;
		}
		int j = 0;
		long[] a = new long[9];
		for (int i = 1; i <= n % 9; i++) {
			a[i] = (n / 9 + 1);
		}
		for (int i = (int) (n % 9 + 1); i <= 9; i++) {
			a[i % 9] = n / 9;
		}
		for (long i = 1; i <= n; i++) {
			++j;
			if (j == 9) {
				j = 0;
			}
			for (int k = 0; k < 9; k++) {
				int t = (j * k) % 9;
				ans += a[k] * a[t];
			}
		}
		out.println(ans);
	}
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main  implements Runnable {
//public static final String FileName = "test";
StreamTokenizer ST;
PrintWriter out;
BufferedReader br;
Scanner in;
static final int inf = 1000000000;

int nextInt() throws IOException{
    ST.nextToken();
    return (int)ST.nval;
}
long nextLong() throws IOException{
    ST.nextToken();
    return (long)ST.nval;
}
String next() throws IOException{
    ST.nextToken();
    return ST.sval;
}
double nextD() throws IOException{
    ST.nextToken();
    return ST.nval;
}
public static void main(String[] args) throws IOException {
   new Thread(new Main()).start();
//	new Main().run();
}

public void run()  {
    try {
    	br = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    	//br = new BufferedReader(new FileReader(new File(FileName+".in")));
    	//out = new PrintWriter(new BufferedWriter(new FileWriter(FileName+".out")));
    	in = new Scanner(br);
        ST = new StreamTokenizer(br);
        solve();
        out.close();
        //in.close();
        br.close();
    }
    catch (IOException e) {
    	e.printStackTrace();
    	throw new IllegalStateException(e);
    }
}

int f(int x) {
	if (x%9==0) return 9;
	return x%9;
}
public void solve() throws IOException {
	int n = nextInt();
	int[] a = new int[10];
	for (int i=1; i<=9; i++) a[i] = n/9;
	if (f(n)!=9)for (int i=1; i<=f(n); i++) a[i]++;
	long res = 0;
	for (int i=1; i<=n; i++)
		res -= n/i;
	for (int i=1; i<=9; i++)
		for (int j=1; j<=9; j++)
			res += 1l*a[i]*a[j]*a[f(i*j)];
	/*int r = 0;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			for (int k=1; k<=n; k++)
				if (i*j!=k && f(f(i)*f(j))==f(k)) r++;
	out.println(r);*/
	out.println(res);

}

}

import java.io.*;

public class Main {
	StreamTokenizer in;
	PrintWriter out;

	public static void main(String args[]) throws IOException
	{
		new Main().run();
	}
	public void run() throws IOException
	{
		in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out=new PrintWriter(new OutputStreamWriter(System.out));

		solve();

		out.flush();
	}
	public int ni() throws IOException
	{
		in.nextToken();
		return (int) in.nval;
	}

	public void solve() throws IOException
	{
		int n=ni();
		long k=0;
		long answ=0;
		for(int i=1;i!=n+1;i++)
			k+=n/i;
		long b[]=new long[10];
		for(int i=1;i!=10;i++)
		{
			b[i]=n/9+ (n%9>=i ? 1 : 0);
		}
		for(int i=1;i!=10;i++)
			for(int j=i + 1;j!=10;j++)
				for(int r=1;r!=10;r++)
				{
					if(((i*j)%9 == 0 ? 9 : (i*j)%9)==r)
						answ+=b[i]*b[j]*b[r];
				}
		answ <<= 1;
		for(int i = 1; i < 10; i++) {
			for(int r = 1; r < 10; r++) {
				if(((i*i)%9 == 0 ? 9 : (i*i)%9)==r)
					answ+=b[i]*b[i]*b[r];
			}
		}
		answ -= k;
		out.print(answ);
	}

}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main implements Runnable {

    private int[] D;

    /////////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        D = new int[1000001];
        Arrays.fill(D, -1);
        ArrayList<Integer>[] v = new ArrayList[10];
        boolean[][] use = new boolean[10][N + 1];
        for (int i = 1; i < 10; i++) {
            v[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= N; i++) {
            int a = d(i);
            v[a].add(i);
            use[a][i] = true;
        }
        long count = 0;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                int a = d(i * j);
                long ans = (long) v[i].size() * v[j].size();
                ans *= v[a].size();
                if (v[a].isEmpty()) continue;
                long lim = v[a].get(v[a].size() - 1);
                for (int k1 = 0; k1 < v[i].size(); k1++) {
                    for (int k2 = 0; k2 < v[j].size(); k2++) {
                        long c = (long)v[i].get(k1) * v[j].get(k2);
                        if (c > lim) break;
                        if (use[a][(int) c]) ans--;
                    }
                }
                count += ans;
            }
        }
        pw.println(count);
    }

    /////////////////////////////////////////////////////////////////
    // Utility functions

    private int d(int i) {
        if (i < 10) return i;
        if (D[i] != -1) return D[i];
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        D[i] = d(sum);
        return D[i];
    }

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException,
            UnsupportedEncodingException {
        if (System.getProperty("ONLINE_JUDGE") == null) {
            System.setIn(new FileInputStream("1"));
        }
        pw = new PrintWriter(System.out);
        in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-9"));
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null)
            throw sError;
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }

}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main implements Runnable {

    private int[] D;

    // ///////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        D = new int[1000001];
        Arrays.fill(D, -1);
        ArrayList<Integer>[] v = new ArrayList[10];
        boolean[][] use = new boolean[10][N + 1];
        for (int i = 1; i < 10; i++) {
            v[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= N; i++) {
            int a = d(i);
            v[a].add(i);
            use[a][i] = true;
        }
        long count = 0;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                int a = d(i * j);
                long ans = (long) v[i].size() * v[j].size();
                ans *= v[a].size();
                if (v[a].isEmpty())
                    continue;
                long lim = v[a].get(v[a].size() - 1);
                for (int k1 = 0; k1 < v[i].size(); k1++) {
                    for (int k2 = 0; k2 < v[j].size(); k2++) {
                        long c = (long) v[i].get(k1) * v[j].get(k2);
                        if (c > lim)
                            break;
                        if (use[a][(int) c])
                            ans--;
                    }
                }
                count += ans;
            }
        }
        pw.println(count);
    }

    private int d(int i) {
        if (i < 10)
            return i;
        if (D[i] != -1)
            return D[i];
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        D[i] = d(sum);
        return D[i];
    }

    // ///////////////////////////////////////////////////////////////
    // Utility functions

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException,
            UnsupportedEncodingException {
        if (System.getProperty("ONLINE_JUDGE") == null) {
            System.setIn(new FileInputStream("1"));
        }
        pw = new PrintWriter(System.out);
        in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-9"));
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null)
            throw sError;
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }

}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main implements Runnable {

    // ///////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        ArrayList<Integer>[] v = new ArrayList[10];
        boolean[][] use = new boolean[10][N + 1];
        for (int i = 1; i < 10; i++) {
            v[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= N; i++) {
            int a = d(i);
            v[a].add(i);
            use[a][i] = true;
        }
        long count = 0;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                int a = d(i * j);
                long ans = (long) v[i].size() * v[j].size();
                ans *= v[a].size();
                if (v[a].isEmpty())
                    continue;
                long lim = v[a].get(v[a].size() - 1);
                for (int k1 = 0; k1 < v[i].size(); k1++) {
                    for (int k2 = 0; k2 < v[j].size(); k2++) {
                        long c = (long) v[i].get(k1) * v[j].get(k2);
                        if (c > lim)
                            break;
                        if (use[a][(int) c])
                            ans--;
                    }
                }
                count += ans;
            }
        }
        pw.println(count);
    }

    private int d(int i) {
        if (i < 10)
            return i;
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        return d(sum);
    }

    // ///////////////////////////////////////////////////////////////
    // Utility functions

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException,
            UnsupportedEncodingException {
        if (System.getProperty("ONLINE_JUDGE") == null) {
            System.setIn(new FileInputStream("1"));
        }
        pw = new PrintWriter(System.out);
        in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-9"));
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null)
            throw sError;
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }

}

import java.util.Scanner;

public class C {
    public static int d(int x) {
        if (x < 10)
            return x;
        int temp = 0;
        while (x > 0) {
            temp += x % 10;
            x /= 10;
        }
        return d(temp);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] D = new int[n + 1];
        for (int i = 2; i * i <= n; i++) {
            if (D[i] != 0)
                continue;
            for (int j = i * i; j <= n; j += i)
                D[j] = i;
        }
        for (int i = 2; i <= n; i++)
            if (D[i] == 0)
                D[i] = i;
        int[] N = new int[n + 1];
        N[1] = 1;
        for (int i = 2; i <= n; i++) {
            int cnt = 1;
            int temp = i;
            while (temp % D[i] == 0) {
                cnt++;
                temp /= D[i];
            }
            N[i] = cnt * N[temp];
        }
        long[] A = new long[10];
        int[] DV = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            DV[i] = d(i);
            A[DV[i]]++;
        }
        long ans = 0;
        long[] V = new long[10];
        for (int i = 1; i < 10; i++)
            for (int j = 1; j < 10; j++)
                for (int k = 1; k < 10; k++) {
                    if (d(j * k) == i) {
                        V[i] += A[j] * A[k];
                    }
                }
        for (int i = 1; i <= n; i++) {
            ans += V[DV[i]];
        }
        for (int i = 1; i <= n; i++) {
            ans -= N[i];
        }
        System.out.println(ans);
    }
}

import java.util.*;
public class Digit{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] v = new long[10];
        for(int i = 1; i <= n ;i++){
            int sum = i % 9 == 0 ? 9 : i % 9;
            v[sum]++;
        }
        long res = 0;
        for(int i = 1; i < 10; i++){
            for(int j = 1 ; j < 10; j++){
                res += v[i] * v[j] * v[(i*j) % 9 == 0 ? 9 : (i*j) % 9];
            }
        }
        for(int i = 1; i <= n ; i++)
            res -= n / i;
        System.out.println(res);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 111118315581
 *
 * @author pttrung
 */
public class C {

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] dp = new int[Math.max(100, n + 1)];
        int[] count = new int[10];
        int[][] hold = new int[n + 1][10];
        for (int i = 1; i < 10; i++) {
            dp[i] = i % 9 == 0 ? 9 : i % 9;
            if (i <= n) {
                count[dp[i]]++;
                hold[i][dp[i]]++;
            }

        }

        for (int i = 10; i < dp.length; i++) {
            dp[i] = dp[i / 10 + i % 10];
            if (i <= n) {
                count[dp[i]]++;
                hold[i][dp[i]]++;
            }
        }
        for (int i = n - 1; i > 0; i--) {
            for (int j = 1; j < 10; j++) {
                hold[i][j] += hold[i + 1][j];
            }
        }
       // System.out.println((long)n*n);
        //System.out.println("HE HE");
        long result = 0;
        for (int i = 1; i <= n; i++) {
            if ((long)i * i <= n) {
                for (int j = i; j <= n; j++) {
                    if ((long)i * j <= n) {
                        hold[i][dp[j]]--;
                        if (dp[i * j] == dp[dp[i] * dp[j]]) {
                            if (i == j) {
                                result += count[dp[i * j]] - 1;
                            } else {
                                result += 2 * count[dp[i * j]] - 2;
                            }
                        } else {
                          //  System.out.println("HE HE" + " " + i + " " + j + " " + i*j) ;
                            if (i == j) {
                                result += count[dp[i * j]];
                            } else {
                                result += 2 * count[dp[i * j]];
                            }
                        }
                    } else {
                        for (int k = 0; k < 10; k++) {
                            if (hold[i][k] > 0) {
                                result +=(long) 2 * hold[i][k] * count[dp[dp[i] * k]];
                            }
                        }
                        break;
                    }
                }
            } else {
                //System.out.println(i);
                for (int j = 0; j < 10; j++) {
                    if (hold[i][j] > 0) {
                        if (j != dp[i]) {
                            result += (long)2 * hold[i][j] * count[dp[dp[i] * j]];
                        } else {
                            result += (long)2 * (hold[i][j] - 1) * count[dp[dp[i] * j]];
                            result += count[dp[dp[i] * j]];
                        }

                    }
                }
                //  result--;
            }
        }
        out.println(result);
//        long test = 0;
//        for(int i = 1; i <= n; i++){
//            for(int j = 1 ; j <= n; j++){
//                for(int k = 1; k <= n; k++){
//                    if(k != i*j && dp[k] == dp[i*j]){
//                        test++;
//                    }else if(dp[i*j] != dp[dp[i]*dp[j]]){
//                        test++;
//                    }
//                }
//            }
//        }
//        out.println(result + " " + test);
        out.close();
    }

    static double distance(Point a, Point b) {
        double total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
        return Math.sqrt(total);
    }

    static class Point {

        int x, y, z;

        public Point(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ProblemC {

	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.valueOf(s.readLine());

		long[] cnt = new long[10];
		for (int i = 1 ; i <= N ; i++) {
			cnt[root(i)]++;
		}

		long answer = 0;
		for (int a = 1 ; a <= N ; a++) {
			int av = root(a);
			for (int bv = 1 ; bv <= 9 ; bv++) {
				int cv = (root(av * bv));
				answer += cnt[bv] * cnt[cv];
			}
			answer -= N / a;
		}
		out.println(answer);
		out.flush();
	}

	public static int root(int a) {
		int val = 0;
		for (char c : String.valueOf(a).toCharArray()) {
			val += c - '0';
		}
		return (val % 9 == 0) ? 9 : val % 9;
	}

	public static void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}

import java.util.*;
import java.io.*;

/**
 * Created by HREN_VAM.
 */

public class C implements Runnable{

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;
    public static final String filename = "c";

    int n;

    int sq(long n){
        if(n < 10)return (int)n;
        int res = 0;
        while(n != 0){
            res += n % 10;
            n /= 10;
        }
        return sq(res);
    }

    public void solve() throws IOException{
        n = nextInt();
        long[] a = new long[10];
        for(int i = 0;i < n;i ++){
            a[sq(i + 1)] ++;
        }
        long res = 0;
        for(int i = 0;i < 10;i ++){
            for(int j = 0;j < 10;j ++){
                res += a[i] * a[j] * a[sq(i * j)];
            }
        }
        for(int i = 1;i <= n;i ++){
            res -= n / i;
        }
        /*for(long i = 1;i <= n;i ++){
            int t = sq(i * i);
            //int ti = sq(i);
            if(a[t] > 0)res -= /*(a[ti] - 1) * (a[ti] - 1) * (a[t] - 1);
        } */
        out.println(res);
    }

    public void run(){
        try{
            Locale.setDefault(Locale.US);
            in = new BufferedReader(new InputStreamReader(System.in));
            //in = new BufferedReader(new FileReader(filename + ".in"));
            out = new PrintWriter(System.out);
            //out = new PrintWriter(new FileWriter(filename + ".out"));
            st = new StringTokenizer("");
            solve();
            out.close();
        } catch(IOException e){
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args){
        new Thread(new C()).start();
    }

    public String nextToken() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException{
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }
}

import java.io.*;
import java.util.*;
import java.lang.*;

public class sol {

	public Scanner in;
	public PrintWriter out;
	public long res;
	public int n, roots[], divs[], prime[], nprime;
	public long byroot[];

	public static void main(String[] args) throws IOException {
		new sol().run();
	}

	public int getRoot(int x) {
		int t = x, tt;
		while (t > 9) {
			tt = 0;
			while (t > 0) {
				tt += t % 10;
				t /= 10;
			}
			t = tt;
		}
		return t;
	}

	public void doPrime() {
		int i, j, erat[] = new int[n + 1];
		prime = new int[n];

		nprime = 1;
		prime[0] = 2;
		for (i = 3; i <= n; i = i + 2) {
			if (erat[i] == 0) {
				prime[nprime] = i;
				nprime++;
				j = i + i;
				while (j <= n) {
					erat[j] = 1;
					j += i;
				}
			}
		}
	}

	public void rDivs(int nn, int val) {
		int i, j;
		long val2, p;
		for (i = nn; i < nprime; i++) {
			p = prime[i];
			val2 = val * p;
			if (!((val2 <= n) & (val2 > 0))) break;
			j = 2;
			while ((val2 <= n) & (val2 > 0)) {
				divs[(int) val2] = divs[val] * j;
				rDivs(i + 1, (int) val2);
				j++;
				val2 *= p;
			}
		}
	}

	public void doDivs() {
		int i, j, k, t, p, d;
		divs = new int[n + 1];
		divs[1] = 1;
		rDivs(0, 1);
	}

	public void run() throws IOException {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		int i, j, k, nn;

		n = in.nextInt();
		nn = n;
		long n2 = n;
		n2 *= n2;
		if (nn < 81) nn = 81;
		byroot = new long[10];
		roots = new int[1000001];
		long byrootx[][] = new long[10][10];
		doPrime();

//		out.println("prime ok");
//		out.flush();

		doDivs();

//		out.println("divs ok");
//		out.flush();

		for (i = 1; i <= nn; i++) {
			roots[i] = getRoot(i);
			if (i <= n) byroot[roots[i]]++;
		}
		for (j = 1; j <= 9; j++)
		for (k = 1; k <= 9; k++)
		byrootx[j][k] = byroot[j] * byroot[k];
		out.flush();
		res = 0;
		int maxdiv = 0;
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= 9; j++)
			for (k = 1; k <= 9; k++)
			if (roots[j * k] == roots[i]) res += byrootx[j][k];
			if (maxdiv < divs[i]) maxdiv = divs[i];
			res -= divs[i];
		}
		out.println(res);
		in.close();
		out.close();
	}
}

//package round10;

import java.io.BufferedOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Scanner;

public class C {
	private Scanner in;
	private PrintWriter out;

	public void solve()
	{
		int n = ni();
		long r = 0;
		for(int i = 1;i <= n;i++){
			r += n / i;
		}

		long[] ct = new long[10];
		for(int i = 1;i <= 9;i++){
			ct[i] = n/9 + (i <= n % 9 ? 1 : 0);
		}

		long all = 0;
		for(int a = 1;a <= 9;a++){
			for(int b = 1;b <= 9;b++){
				all += ct[a] * ct[b] * ct[d(a*b)];
//				tr(a, b, d(a*b), all);
			}
		}
		out.println(all - r);
	}

	private int d(int a)
	{
		int m = a%9;
		return m == 0 ? 9 : m;
	}

	public void run() throws Exception
	{
//		in = new Scanner(new StringReader("9"));
		in = new Scanner(System.in);
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		out = new PrintWriter(System.out);

//		int n = in.nextInt();
		int n = 1;
		for(int i = 1;i <= n;i++){
			long t = System.currentTimeMillis();
			solve();
			out.flush();
//			System.err.printf("%04d/%04d %7d%n", i, n, System.currentTimeMillis() - t);
		}
	}

	public static void main(String[] args) throws Exception
	{
		new C().run();
	}

	private int ni() { return Integer.parseInt(in.next()); }
	private static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }
	private void tra(int[] a) {System.out.println(Arrays.toString(a));}
	private void tra(int[][] a)
	{
		for(int[] e : a){
			System.out.println(Arrays.toString(e));
		}
	}

}

import java.util.Scanner;

public class C {
    public static int computeD(int x) {
        int res = 0;
        while (true) {
            while (x > 0) {
                res += (x % 10);
                x /= 10;
            }
            if (res < 10)
                return res;
            x = res;
            res = 0;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n + 1];
        long[] count = new long[10];
        for (int i = 1; i <= n; i++) {
            int tmp = i;
            int res = 0;
            while (tmp > 0) {
                res += tmp % 10;
                tmp /= 10;
            }
            if (res < 10)
                d[i] = res;
            else
                d[i] = d[res];
            count[d[i]]++;
        }
        long res = 0;
        long remove = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                int mul = computeD(i * j);
                long t = count[i] * count[j] * count[mul];
                res += t;
            }
        }
        for (int i = 1; i <= n; i++) {
            long l = 1, h = n, mid;
            while (l < h) {
                mid = l + (h - l) / 2;
                if (mid * i <= n) {
                    l = mid + 1;
                } else {
                    h = mid;
                }
            }
            if (i * l > n)
                l--;
            remove += (l);
        }
        System.out.println(res - remove);
    }
}

import java.io.*;
import java.util.*;

public class DigitalRoot
{
	public Scanner in = new Scanner(System.in);
	public PrintStream out = System.out;

	public int N;

	public void main()
	{
		N = in.nextInt();

		int x, y, z;
		long res = 0;

		long A, B, C;
		int a, b;

		for(z=1;z<=9;++z) for(x=1;x<=9;++x) for(y=1;y<=9;++y) if(z == d(x*y))
		{
			C = count(9, z);
			A = count(9, x);
			B = count(9, y);

			res += A * B * C;

			for(int k=0; k*9+x <=N;++k)
			{
				a = k*9*9 + 9*x;
				b = k*9*y + x*y;
				res -= count(a, b);
			}
		}

		out.println(res);
	}//end public void main()

	public int d(int x)
	{
		if(x%9 == 0) return 9;
		return x%9;
	}

	public int count(int a, int b)
	{
		if(N < b) return 0;
		return (N - b)/a + 1;
	}

	public static void main(String[] args)
	{
		(new DigitalRoot()).main();
	}
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Solution {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    int count(int mod, int n) {
        int res = n / 9 + ((n % 9 >= mod) ? 1 : 0);
        return res;
    }

    int sum(int a) {
        int res = 0;
        while (a > 0) {
            res += a % 10;
            a /= 10;
        }
        return res;
    }

    int d(int a) {
        int s = sum(a);
        if (s < 10)
            return s;
        else
            return d(s);
    }

    void solve() throws IOException {
        int n = ni();
        long[] was = new long[10];
        for (int i = 1; i <= n; ++i)
            was[d(i)]++;
        long res = 0;
        for (int i = 1; i < 10; ++i)
            for (int j = 1; j < 10; ++j)
                for (int k = 1; k < 10; ++k)
                    if (d(i * j) == k) {
                        res += was[i] * was[j] * was[k];
                    }
        for (int i = 1; i <= n; ++i) {
            res -= n / i;
        }
        out.println(res);
    }

    public Solution() throws IOException {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    String ns() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

    public static void main(String[] args) throws IOException {
        new Solution();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Problem solution.
 * @author Andrew Porokhin, andrew.porokhin@gmail.com
 */
public class Problem10C implements Runnable {
    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) {
        new Problem10C().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(9000);
        } finally {
            out.flush();
            out.close();
        }
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    static final long s(final long m) {
        final String mString = Long.toString(m);
        long result = (mString.charAt(0) - '0');
        for (int i = 1; i < mString.length(); i++) {
            result += mString.charAt(i) - '0';
        }
        return result;
    }

    static final long d(final long m) {
        return (m > 9) ? d(s(m)) : m;
    }

    static final long fast_d(final long m) {
        if (m == 0) {
            return 0;
        }

        long rest = m % 9;
        return rest == 0 ? 9 : rest;
    }

    void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        long[] d_cache = new long[10];
        if (n < 9) {
          for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
              if (fast_d(i * j) <= n) {
                d_cache[j]++;
              }
            }
          }
        } else {
          long ndiv9 = n / 9;
          long nmod9 = n % 9;

          for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++ ) {
              int mul = i * j % 9;
              int normMul = (mul == 0 ? 9 : mul);

              long incr1 = (normMul <= nmod9) ? 1 : 0;
              long incr2 = ndiv9 + ((i <= nmod9) ? 1 : 0);
              long res = (ndiv9 + incr1) * incr2;
              d_cache[j] += res;
            }
          }
        }

        long result = 0;
        for (int i = 1; i <= n; i++) {
          int index = (int) fast_d(i);
          long v = d_cache[index] - n / i;
          result += v;
        }

        System.out.println(result);
    }
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
    public static void main(String[] args) throws IOException {

        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int N = nextInt();

        if (N == 1) {
            out.println(0);
            out.close();
            return;
        }

        long[] cnt = new long [9];
        for (int i = 1; i <= N; i++)
            cnt[i % 9]++;

        long ans = 0;
        int MIN = min(9, N + 1);

        for (int C = 0; C < MIN; C++) {
            for (int A = 0; A < MIN; A++) {
                for (int B = 0; B < MIN; B++) {
                    if ((A * B) % 9 == C) {
                        ans += cnt[A] * cnt[B] * cnt[C];
                    }
                }
            }
        }

        for (int x = 1; x <= N; x++) {
            ans -= N / x;
        }

        out.println(ans);
        out.close();
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }

        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }

    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();

            if (s == null) {
                return true;
            }

            st = new StringTokenizer(s);
        }

        return false;
    }
}

import java.io.BufferedReader;
import static java.lang.Math.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class problemC implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(new problemC()).start();
	}

	long kol(long n, long mod) {
		if(mod == 0) return n / 9;
		else {
			if(n < mod) return 0;
			else {
				long res = n / 9;
				if(n % 9 >= mod) ++res;
				return res;
			}
		}
	}

	void solve() throws IOException {
		long n = nextInt();
		long res = 0;

		for(long a = 0; a < 9; ++a)
			for(long b = 0; b < 9; ++b)
				for(long c = 0; c < 9; ++c) {
					if((a * b) % 9 == c) {
						long ak = kol(n, a);
						long bk = kol(n, b);
						long ck = kol(n, c);
						if( res + ak * bk * ck < 0)
							System.in.read();
						res += ak * bk * ck;

					}
				}
		for(long a = 1; a <= n; ++a)
			res -= n / a;
		System.out.println(res);
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			// in = new BufferedReader(new FileReader(new File("input.txt")));
			out = new PrintWriter(System.out);
			// out = new PrintWriter(new File("output.txt"));
			solve();
			out.flush();
			out.close();
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	String nextLine() throws IOException {
		tok = null;
		return in.readLine();
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Root implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        long res = 0;
        int[] am = new int[10];
        for (int i = 1; i <= n; ++i) {
            int sum = (i % 9 + 8) % 9 + 1;
            ++am[sum];
        }
        for (int a = 1; a < 10; ++a) {
            for (int b = 1; b < 10; ++b) {
                int c = ((a * b) % 9 + 8) % 9 + 1;
                res += (long) am[a] * am[b] * am[c];
            }
        }
        for (int a = 1; a <= n; ++a) {
            res -= n / a;
        }
        writer.println(res);
    }

    public static void main(String[] args) {
        new Root().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    private static class TaskB {

        static final long max = 1000000000000000000L;
        static final double eps = 0.0000001;
        static final long mod = 1000000007;
        static int N, M, K;
        static long X, Y;
        boolean V[][];
        int A[][], total;

        void solve(InputReader in, PrintWriter out) throws IOException {

            int N = in.nextInt();
            long res = 0;
            int[] D = new int[10];
            for (int i = 1; i <= N; ++i) {
                int sum = (i % 9 + 8) % 9 + 1;
                ++D[sum];
            }
            for (int A = 1; A < 10; ++A) {
                for (int B = 1; B < 10; ++B) {
                    int C = ((A * B) % 9 + 8) % 9 + 1;
                    res += D[A] * D[B] * D[C];
                }
            }

            for (int i = 1; i <= N; ++i) {
                res -= N / i;
            }

            out.println(res);
        }

        long gcd(long a, long b) {
            if (b == 0) return a;
            return gcd(b, a % b);
        }

        long lcm(long a, long b) {
            return (a * b) / gcd(a, b);
        }

        boolean isPrime(long n) {
            if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
                return false;
            for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)
                if (n % i == 0)
                    return false;
            return true;
        }

        double dist(double X1, double Y1, double X2, double Y2) {
            return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
        }

        boolean isEqual(double A, double B) {
            return Math.abs(A - B) < eps;
        }

        long extendEuc(long A, long B) {

            long lastX = 1, lastY = 0, temp;
            X = 0;
            Y = 1;

            while (B != 0) {
                long Q = A / B;
                long R = A % B;

                A = B;
                B = R;

                temp = X;
                X = lastX - Q * X;
                lastX = temp;

                temp = Y;
                Y = lastY - Q * Y;
                lastY = temp;
            }

            X = lastX;
            Y = lastY;

            return A;
        }
    }

    private static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public InputReader(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean ready() {
            try {
                return br.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

import java.io.*;

/**
 * Created by James on 1/29/2015.
 */

public class Driver {
    public static void main(String [] args) throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(scanner.readLine().trim()), count = 0;

        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                for (int k = 1; k <= N; ++k) {
                    if (d(d(i) * d(j)) == d(k) && i * j != k) {
                        out.println(i + " " + j + " " + k);
                        count++;
                    }
                }
            }
        }

        out.println(count);
        out.close();
    }

    private static int d(int N) {
        if (N < 10) {
            return N;
        }

        String num = Integer.toString(N);
        int sum = 0;

        for (int i = 0; i < num.length(); ++i) {
            sum += Integer.parseInt(String.valueOf(num.charAt(i)));
        }

        return d(sum);
    }
}

import java.util.*;

public class LRBS {

    static int sum(int n){
        int y =0;

        while(n!=0){
            y+= (n%10);
            n = n/10;
        }
        return y;
    }
    public static  void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int a[] = new int[1000001];

        for(int i=1;i<10;i++){
            a[i] = i;
        }

        for(int i=10;i<a.length;i++){
            a[i] = a[sum(i)];
        }

         int digit[]=  new int[10];

        for(int i=1;i<=n;i++){
            digit[a[i]]++;
        }

        long res = 0;
        for(int i=1;i<=9&&i<=n;i++){
            for(int j=1;j<=9&&j<=n;j++){

                     res += digit[i]*digit[j]*digit[a[i*j]];

            }
        }
        for(int i=1;i<=n;i++){
            res -= (n/i);
        }

        System.out.println(res);
    }
}

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
//        InputStream inputStream = new FileInputStream("sum.in");
        OutputStream outputStream = System.out;
//        OutputStream outputStream = new FileOutputStream("sum.out");

//        Path path = Paths.get(URI.create("file:///foo/bar/Main.java"));
//        System.out.print(path.getName(200));

//        Path p = Paths.get("/foo/bar/Main.java");
//        for (Path e : p) {
//            System.out.println(e);
//        }

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Answer solver = new Answer();
        solver.solve(in, out);
        out.close();
    }
}

class Answer {
    private final int INF = (int) (1e9 + 7);
    private final int MOD = (int) (1e9 + 7);
    private final int MOD1 = (int) (1e6 + 3);
    private final long INF_LONG = (long) (1e18 + 1);
    private final double EPS = 1e-9;

    public void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();

        int[][] a = new int[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                a[i][j] = (i * j) % 9;
            }
        }

        int[] b = new int[9];
        for (int i = 1; i <= n; i++) {
            b[i % 9]++;
        }

        long x = 0;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                x += b[i] * b[j] * b[a[i][j]];
            }
        }

        long y = 0;
        for (int i = 1; i <= n; i++) {
            y += n / i;
        }

        out.print(x - y);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
}

import java.util.Scanner;

public class CF10C {
	private static int[] cnt(int n) {
		int[] res = new int[9];
		for (int i = 0; i < 9; i++) {
			res[i] = n / 9 + (n % 9 >= i && i != 0 ? 1 : 0);
		}
		return res;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long res = 0;
		for (int i = 1; i <= n; i++) {
			int[] cnt = cnt(n / i);
			int[] cnt_n = cnt(n);
			for (int j = 0; j < 9; j++) {
				res += cnt[j] * (cnt_n[(i * j) % 9] - 1);
				res += (cnt_n[j] - cnt[j]) * cnt_n[(i * j) % 9];
			}
		}
		System.out.println(res);
		sc.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot
{

	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(in.readLine());
		int [] Nd = new int[10];
		for (int i = 1; i<=N%9; ++i)
		{
			Nd[i] = N/9 + 1;
		}
		for(int i = N%9+1; i<10; ++i)
		{
			Nd[i] = N/9;
		}
		int t = 0;
		for(int d1 = 1; d1 < 10; ++d1)
			for(int d2 = 1; d2 < 10; ++d2)
				t+=Nd[d1]*Nd[d2]*Nd[digitalRoot(d1*d2)];
		for(int x = 1; x <= N; ++x)
		{
			t-= Math.floor(1.0*N/x);
		}
		System.out.println(t);
	}

	public static int digitalRoot(int n)
	{
		return ((n-1)%9)+1;
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot
{

	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(in.readLine());
		int [] Nd = new int[10];
		for (int i = 1; i<=N%9; ++i)
		{
			Nd[i] = N/9 + 1;
		}
		for(int i = N%9+1; i<10; ++i)
		{
			Nd[i] = N/9;
		}
		long t = 0;
		for(int d1 = 1; d1 < 10; ++d1)
			for(int d2 = 1; d2 < 10; ++d2)
				t+=Nd[d1]*Nd[d2]*Nd[digitalRoot(d1*d2)];
		for(int x = 1; x <= N; ++x)
		{
			t-= Math.floor(1.0*N/x);
		}
		System.out.println(t);
	}

	public static int digitalRoot(int n)
	{
		return ((n-1)%9)+1;
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot
{

	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(in.readLine());
		long [] Nd = new long[10];
		for (int i = 1; i<=N%9; ++i)
		{
			Nd[i] = N/9 + 1;
		}
		for(int i = N%9+1; i<10; ++i)
		{
			Nd[i] = N/9;
		}
		long t = 0;
		for(int d1 = 1; d1 < 10; ++d1)
			for(int d2 = 1; d2 < 10; ++d2)
				t+=Nd[d1]*Nd[d2]*Nd[digitalRoot(d1*d2)];
		for(int x = 1; x <= N; ++x)
		{
			t-= Math.floor(1.0*N/x);
		}
		System.out.println(t);
	}

	public static int digitalRoot(int n)
	{
		return ((n-1)%9)+1;
	}

}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws FileNotFoundException, IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();

	}
}

class Circles {
	Pair point;
	double second;

	Circles(Pair point, double second) {
		this.point = point;
		this.second = second;
	}
}

class Pair {
	double first;
	double second;

	Pair(double first, double second) {
		this.first = first;
		this.second = second;
	}

}

// pair problem can be done using stack
class TaskB {
	int MAXN = (int) 1e9 + 7;
	double t1;
	double t2;
	double eps = 1e-10;
	double d[];

	void solve(int testNumber, InputReader in, PrintWriter pw) {
		int n = in.nextInt();
		int div[] = new int[n + 1];
		for (int i = 1; i <= n; ++i) {
			for (int j = i; j <= n; j += i) {
				div[j]++;
			}
		}
		int cnt[] = new int[10];
		long dig[] = new long[n + 1];
		for (int i = 1; i <= n; ++i) {
			int d_sum = 0;
			int num = i;
			while (num > 0) {
				int d = num % 10;
				d_sum = (d_sum + d);
				if (d_sum > 9) {
					d_sum -= 9;
				}
				num /= 10;
			}
			cnt[d_sum]++;
			dig[i] = (div[i]) * 1L * (div[i] - 1);
		}
		pw.println(Arrays.toString(div));
		pw.println(Arrays.toString(cnt));
		long ans = 0;
		for (int j = 0; j < 10; ++j) {
			for (int k = 0; k < 10; ++k) {
				int prod = j * k;
				int num1 = prod % 10;
				num1 += prod / 10;
				if (num1 > 9) {
					num1 -= 9;
				}
				ans += (cnt[j] * 1L * cnt[k] * 1L * cnt[num1]);
			}
		}

		pw.println(ans);
	}

	long pow(int n, int m) {
		if (m == 0)
			return 1;
		long ans = pow(n, m / 2);
		ans = (ans * ans);
		if (m % 2 == 1) {
			ans = (ans * n);
		}
		return ans;
	}

	double pow(double n, int m) {
		if (m == 0)
			return 1;
		double ans = pow(n, m / 2);
		ans = (ans * ans);
		if (m % 2 == 1) {
			ans = (ans * n);
		}
		return ans;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

import java.util.Scanner;

public class DigitalRoot {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int digits[] = new int[9];
		long result = 0;
		for (int i = 1; i <= n; i++) {
			digits[i%9]++;
			result -= (n/i);
		}
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				result += digits[i]*digits[j]*digits[(i*j)%9];
			}
		}
		System.out.println(result);
	}

}

import java.util.Scanner;

/**
 * Created by vasily on 09.04.17.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            long cnt = 0;
            int[] ds = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                int m9 = ds[i] == 0 ? (i - 1) % 9 : ds[i];
                for (int j = 1; j <= N; j++) {
                    int mj9 = ds[j] == 0 ? (j - 1) % 9 : ds[j];
                    if (j >= i) {
                        for (int k = 1; k <= N; k++) {
                            int mk = ds[k] == 0 ? (k - 1) % 9 : ds[k];
                            if (i*j != k && mk == ((1 + m9) * (1 + mj9) - 1) % 9) {
                                cnt++;
                            }
                        }
                    }
                }
            }
            System.out.println(2*cnt);
        }
    }
}

import java.util.Scanner;

/**
 * Created by vasily on 09.04.17.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            long cnt = 0;
            int[] ds = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                int m9 = ds[i] == 0 ? (i - 1) % 9 : ds[i];
                for (int j = 1; j <= N; j++) {
                    int mj9 = ds[j] == 0 ? (j - 1) % 9 : ds[j];
                    if (j >= i) {
                        for (int k = 1; k < i*j && k <= N; k++) {
                            int mk = ds[k] == 0 ? (k - 1) % 9 : ds[k];
                            if (mk == ((1 + m9) * (1 + mj9) - 1) % 9) {
                                cnt++;
                            }
                        }
                    }
                }
            }
            System.out.println(2*cnt);
        }
    }
}

import java.util.Scanner;

/**
 * Created by vasily on 09.04.17.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            long cnt = 0;
            int[] ds = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                int m9 = ds[i] == 0 ? (i - 1) % 9 : ds[i];
                for (int j = 1; j <= N; j++) {
                    int mj9 = ds[j] == 0 ? (j - 1) % 9 : ds[j];
                    for (int k = 1; k <= N; k++) {
                        int mk = ds[k] == 0 ? (k - 1) % 9 : ds[k];
                        if (i*j != k && mk == ((1 + m9) * (1 + mj9) - 1) % 9) {
                            System.out.println(i + "*" + j + "=" + k);
                            cnt++;
                        }
                    }
                }
            }
            System.out.println(cnt);
        }
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class trial
{
	static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input)
    {
        reader = new BufferedReader( new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static long nextInt() throws IOException
    {
        return Long.parseLong( next() );
    }
	static PrintWriter writer;
	static void outit(OutputStream outputStream)
	{
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}
	static void print(Object...objects) {
		for (int i = 0; i < objects.length; i++)
		{
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	static void println(Object...objects)
	{
		print(objects);
		writer.println();
	}

	static void close()
	{
		writer.close();
	}

	static void flush() {
		writer.flush();
	}
	public static void print_a(long [] a)
    {
    	for(long i : a)
    	{
    		print(i+" ") ;
    	}
    	println() ;
    }
    public static void main(String [] args) throws IOException
    {
    	init(System.in) ;
    	outit(System.out) ;
//    	int t = (int) nextInt() ;
//    	for(int i =0 ; i<t ; i++)
    	output() ;
        flush();
        close();
    }
    public static void output() throws IOException
    {
    	int n = (int)nextInt() ;
    	int [] ctr = new int[9] ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		ctr[i%9]++ ;
    	}
    	boolean [] prime = new boolean[n+1] ;
        int [] fac = new int [n+1] ;
        Arrays.fill(prime,true) ;
        Arrays.fill(fac,-1);
        for(int i=2; i*i<=n; i++)
        {
            if (prime[i])
            {
                for (int j=i*i; j<=n; j+=i)
                {
                	if(prime[j])
                	{
                		prime[j] = false;
                		fac[j] = i ;
                	}
                }
            }
        }
        for(int i = 2; i<=n ; i++)
        {
        	if(fac[i]==-1)
        	{
        		fac[i] = i ;
        	}
        }
        fac[1] =1 ;
    	int [] n_fac = new int[n+1] ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>() ;
    		int temp = i ;
    		while(temp!=1)
    		{
    			int p = fac[temp] ;
    			if(hm.containsKey(p))
    			{
    				hm.put(p,hm.get(p)+1) ;
    			}
    			else
    			{
    				hm.put(p,1) ;
    			}
    			temp/=p ;
    		}
    		int ans = 1 ;
    		for(int p : hm.keySet())
    		{
    			ans = ans*(hm.get(p)+1) ;
    		}
    		n_fac[i] =ans ;
    	}
    	long ans = 0 ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		int m = i%9 ;
    		for(int j=0 ; j<9 ; j++)
    		{
    			for(int k = 0; k<9 ; k++)
    			{
    				if(j!=k)
    				{
    					if(((j%9)*(k%9))%9==m)
    					{
    						ans+=ctr[j]*ctr[k];
//    						println(i+" "+j+" "+k) ;
    					}
    				}
    			}
    		}
    		for(int j = 0; j<9 ; j++)
    		{
    			if((j*j)%9==m)
    			{
    				ans+=ctr[j]*ctr[j] ;
    			}
    		}
    		ans-= n_fac[i] ;
    	}
    	println(ans) ;
    }
}

import java.util.Scanner;

public class DigitalRoot {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        //we count the d for each number between 1 and n
        int[] count = new int[9];
        for (int i=1;i<=n;i++){
            count[i%9]++;
        }

        //we count all the combination possible according to Billy method
        int countAll=0;
        for(int a=0;a<9;a++){
            for(int b=0;b<9;b++){
                countAll+=count[a%9]*count[b%9]*count[a*b%9];
            }
        }

        //we remove the one who realy match;
        for(int i=1;i<=n;i++){
            countAll-=n/i;
        }

        System.out.println(countAll);

    }
}

public class Main {
	public static void main(String[] args)
	{
		int N = (new java.util.Scanner(System.in).nextInt());
		int q = N / 9;
		int r = N % 9;

		long ans = 0;
		for (int i1 = 0; i1 < 9; i1++)
			for (int i2 = 0; i2 < 9; i2++)
				for (int i3 = 0; i3 < 9; i3++)
				{
					if((i1 * i2) % 9 == i3 % 9)
					{
						int a1 = q + ((r >= i1 && i1>0)?1:0);
						int a2 = q + ((r >= i2 && i2>0)?1:0);
						int a3 = q + ((r >= i3 && i3>0)?1:0);
						ans += a1 * a2 * a3;
					}
				}

		for (int i = 1; i <= N; i++)
			ans -= N / i;

		System.out.println(ans);
	}
}

import java.io.*;

public class C {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main (String[] args) throws IOException {
        long n = Integer.parseInt(br.readLine());
        long ans = 0;
        for (int a = 1; a <= 9; a++) {
            for (int b = 1; b <= 9; b++) {
                ans += f(n, a * b) * f(n, a) * f(n, b);
            }
        }
        System.out.println(ans);
        for (int A = 1; A <= n; A++) {
            ans -= n / A;
        }
        System.out.println(ans);
    }
    private static long f (long n, long x) {
        long y = (x - 1) % 9 + 1;
        return y <= n ? 1 + (n - y) / 9 : 0;
    }
}

import java.io.*;
import java.util.*;

public class Task {
    public static int n,p1,p2,p3,t1,t2,energy;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int s = 0;
        int[] c = new int[9];

        for(int i=1;i<n+1;i++){
            s-= n/i;
            c[ i % 9 ] = c[ i % 9 ] + 1;
        }

        for(int i=0;i<9;i++)
            for(int j=0;j<9;j++){
                s+= c[i] * c[j] * c[ i * j % 9 ];
            }

        System.out.print(s);

        /*
        n = int(raw_input())
        s = 0
        c = [0]*9
        for i in range(1, n + 1):
                s -= n / i
                c[i % 9] = c[i % 9] + 1
        for i in range(9):
                for j in range(9):
                        s += c[i] * c[j] * c[i * j % 9]
        print s

         * */

    }

}

import java.util.*;
public class Digit{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] v = new int[10];
        for(int i = 1; i <= n ;i++){
            int sum = i % 9 == 0 ? 9 : i % 9;
            v[sum]++;
        }
        int res = 0;
        for(int i = 1; i < 10; i++){
            for(int j = 1 ; j < 10; j++){
                res += v[i] * v[j] * v[(i*j) % 9 == 0 ? 9 : (i*j) % 9];
            }
        }
        for(int i = 1; i <= n ; i++)
            res -= n / i;
        System.out.println(res);
    }
}

import java.util.*;
public class Digit{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] v = new int[10];
        for(int i = 1; i <= n ;i++){
            int sum = i % 9 == 0 ? 9 : i % 9;
            v[sum]++;
        }
        long res = 0;
        for(int i = 1; i < 10; i++){
            for(int j = 1 ; j < 10; j++){
                res += v[i] * v[j] * v[(i*j) % 9 == 0 ? 9 : (i*j) % 9];
            }
        }
        for(int i = 1; i <= n ; i++)
            res -= n / i;
        System.out.println(res);
    }
}

import java.util.*;
public class Digital {
public static void main(String [] args){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int array[]=new int[10];
int a=n%9;
for(int i=1;i<=9;i++){
array[i]=n/9;
}
for(int i=1;i<=n%9;i++){
array[i]++;
}
long ans=0;
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
int temp=i*j%9;
if(temp==0)
temp=9;
ans+=array[i]*array[j]*array[temp];
}
}
for(int i=1;i<=n;i++){
ans-=n/i;
}
System.out.println(ans);
}
}

import java.io.*;
import java.util.*;
import java.math.*;
public class DigitRoot {
	int n;

	public static void main(String [] args) {
		new DigitRoot().solve();
	}

	private void solve() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int [] root = new int[10000001];
		int [] repeat = new int[10];
		for(int i = 1; i<=Math.max(n, 10); ++i) {
			root[i] = d(i);
		}
		for(int c = 1; c<=n; ++c) {
			++repeat[root[c]];
		}
		long ans = 0;
		for(int i = 1; i<=Math.min(n, 9); i++) {
			for(int j = 1; j<=Math.min(n, 9); j++) {
				for(int k = 1; k<=Math.min(n, 9); k++) {
					if(root[k*j] == root[i]) {
						ans += (long)repeat[i] * (long)repeat[j] * (long)repeat[k];
					}
				}
			}
		}
		long abc = 0, valid=0;
		for(int i = 1; i<=n; i++) {
			int k = n/i;

			for(int j = 1; j<=k; j++) {
				++abc;

				if(root[i*j] == root[root[i]*root[j]]){
					++valid;
				}
			}
		}
		System.out.println(abc+ans-2*valid);

	}
	private int d(int x) {
		int res = 0;
		while(x>0) {
			res+=x%10;
			x /= 10;
		}
		if(res>=10) return d(res);
		return res;
	}

}

import java.io.*;
import java.util.*;
import java.math.*;
public class DigitRoot {
	int n;

	public static void main(String [] args) {
		new DigitRoot().solve();
	}

	private void solve() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int [] root = new int[10000001];
		int [] repeat = new int[11];
		for(int i = 1; i<=Math.max(n, 81); ++i) {
			root[i] = d(i);
		}
		for(int c = 1; c<=n; ++c) {
			++repeat[root[c]];
		}
		long ans = 0;
		for(int i = 1; i<=Math.min(n, 9); i++) {
			for(int j = 1; j<=Math.min(n, 9); j++) {
				for(int k = 1; k<=Math.min(n, 9); k++) {
					if(root[k*j] == root[i]) {
						ans += repeat[i] * repeat[j] * repeat[k];
					}
				}
			}
		}
		long abc = 0, valid=0;
		for(int i = 1; i<=n; i++) {
			int k = n/i;

			for(int j = 1; j<=k; j++) {
				++abc;

				if(root[i*j] == root[root[i]*root[j]]){
					++valid;
				}
			}
		}
		System.out.println(abc+ans-2*valid);

	}
	private int d(int x) {
		int res = 0;
		while(x>0) {
			res+=x%10;
			x /= 10;
		}
		if(res>=10) return d(res);
		return res;
	}

}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main  implements Runnable {
//public static final String FileName = "test";
StreamTokenizer ST;
PrintWriter out;
BufferedReader br;
Scanner in;
static final int inf = 1000000000;

int nextInt() throws IOException{
    ST.nextToken();
    return (int)ST.nval;
}
long nextLong() throws IOException{
    ST.nextToken();
    return (long)ST.nval;
}
String next() throws IOException{
    ST.nextToken();
    return ST.sval;
}
double nextD() throws IOException{
    ST.nextToken();
    return ST.nval;
}
public static void main(String[] args) throws IOException {
   new Thread(new Main()).start();
//	new Main().run();
}

public void run()  {
    try {
    	br = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    	//br = new BufferedReader(new FileReader(new File(FileName+".in")));
    	//out = new PrintWriter(new BufferedWriter(new FileWriter(FileName+".out")));
    	in = new Scanner(br);
        ST = new StreamTokenizer(br);
        solve();
        out.close();
        //in.close();
        br.close();
    }
    catch (IOException e) {
    	e.printStackTrace();
    	throw new IllegalStateException(e);
    }
}

int f(int x) {
	if (x%9==0) return 9;
	return x%9;
}
public void solve() throws IOException {
	int n = nextInt();
	int[] a = new int[10];
	for (int i=1; i<=9; i++) a[i] = n/9;
	for (int i=1; i<=f(n); i++) a[i]++;
	long res = 0;
	for (int i=1; i<=n; i++)
		res -= n/i;
	for (int i=1; i<=9; i++)
		for (int j=1; j<=9; j++)
			res += 1l*a[i]*a[j]*a[f(i*j)];
	/*int r = 0;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			for (int k=1; k<=n; k++)
				if (i*j!=k && f(f(i)*f(j))==f(k)) r++;
	out.println(r);*/
	out.println(res);

}

}

import java.io.*;

public class Main {
	StreamTokenizer in;
	PrintWriter out;

	public static void main(String args[]) throws IOException
	{
		new Main().run();
	}
	public void run() throws IOException
	{
		in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out=new PrintWriter(new OutputStreamWriter(System.out));

		solve();

		out.flush();
	}
	public int ni() throws IOException
	{
		in.nextToken();
		return (int) in.nval;
	}

	public void solve() throws IOException
	{
		int n=ni();
		long k=0;
		long answ=0;
		for(int i=1;i!=n+1;i++)
			k+=n/i;
		int b[]=new int[10];
		for(int i=1;i!=10;i++)
		{
			b[i]=n/9+ (n%9>=i ? 1 : 0);
		}
		for(int i=1;i!=10;i++)
			for(int j=i + 1;j!=10;j++)
				for(int r=1;r!=10;r++)
				{
					if(((i*j)%9 == 0 ? 9 : (i*j)%9)==r)
						answ+=b[i]*b[j]*b[r];
				}
		answ <<= 1;
		for(int i = 1; i < 10; i++){
			for(int r = 1; r < 10; r++) {
				if(((i*i)%9 == 0 ? 9 : (i*i)%9)==r)
					answ+=b[i]*b[i]*b[r];
			}
		}
		answ -= k;
		out.print(answ);
	}

}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main implements Runnable {

    private int[] D;

    /////////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        D = new int[1000001];
        Arrays.fill(D, -1);
        ArrayList<Integer>[] v = new ArrayList[10];
        boolean[][] use = new boolean[10][N + 1];
        for (int i = 1; i < 10; i++) {
            v[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i <= N; i++) {
            int a = d(i);
            v[a].add(i);
            use[a][i] = true;
        }
        long count = 0;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                int a = d(i * j);
                long ans = (long) v[i].size() * v[j].size();
                if (v[a].isEmpty()) continue;
                long lim = v[a].get(v[a].size() - 1);
                for (int k1 = 0; k1 < v[i].size(); k1++) {
                    for (int k2 = 0; k2 < v[j].size(); k2++) {
                        long c = (long)v[i].get(k1) * v[j].get(k2);
                        if (c > lim) break;
                        if (use[a][(int) c]) ans--;
                    }
                }
                count += ans;
            }
        }
        pw.println(count);
    }

    /////////////////////////////////////////////////////////////////
    // Utility functions

    private int d(int i) {
        if (i < 10) return i;
        if (D[i] != -1) return D[i];
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        D[i] = d(sum);
        return D[i];
    }

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException,
            UnsupportedEncodingException {
        if (System.getProperty("ONLINE_JUDGE") == null) {
            System.setIn(new FileInputStream("1"));
        }
        pw = new PrintWriter(System.out);
        in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-9"));
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null)
            throw sError;
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }

}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Runnable {

    //////////////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        long all = (long) N * N;
        int lim = Math.min(N, 9);
        for (int i = 1; i <= lim; i++) {
            for (int j = 1; j <= lim; j++) {
                if (i * j <= lim) {
                    all--;
                } else {
                    int v = calcD(i * j);
                    if (v > N)
                        all--;
                }
            }
        }
        for (int i = lim + 1; i * i <= N; i++) {
            all--;
        }
        pw.println(all);
    }

    private int calcD(int i) {
        if (i < 10) return i;
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        return calcD(sum);
    }

    //////////////////////////////////////////////////////////////////////
    // Utility functions

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException {
        //System.setIn(new FileInputStream("1"));
        in = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null) {
            throw sError;
        }
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }
}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Runnable {

    //////////////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        long all = (long) N * N;
        int lim = Math.min(N, 9);
        for (int i = 1; i <= lim; i++) {
            for (int j = 1; j <= lim; j++) {
                if (i * j <= lim) {
                    all--;
                } else {
                    int v = calcD(i * j);
                    if (v > N)
                        all--;
                }
            }
        }
        pw.println(all);
    }

    private int calcD(int i) {
        if (i < 10) return i;
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        return calcD(sum);
    }

    //////////////////////////////////////////////////////////////////////
    // Utility functions

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException {
        //System.setIn(new FileInputStream("1"));
        in = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null) {
            throw sError;
        }
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }
}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Runnable {

    //////////////////////////////////////////////////////////////////////
    // Solution

    private void solve() throws Throwable {
        int N = nextInt();
        long all = (long) N * N;
        int lim = Math.min(N, 9);
        for (int i = 1; i <= lim; i++) {
            for (int j = 1; j <= lim; j++) {
                if (i * j <= 9) {
                    all--;
                } else {
                    int v = calcD(i * j);
                    if (v > N) all--;
                }
            }
        }
        pw.println(all);
    }

    private int calcD(int i) {
        if (i < 10) return i;
        int sum = 0;
        while (i > 0) {
            sum += (i % 10);
            i /= 10;
        }
        return calcD(sum);
    }

    //////////////////////////////////////////////////////////////////////
    // Utility functions

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException {
        //System.setIn(new FileInputStream("1"));
        in = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null) {
            throw sError;
        }
    }

    public void run() {
        try {
            initStreams();
            solve();
        } catch (Throwable e) {
            sError = e;
        } finally {
            if (pw != null)
                pw.close();
        }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 111118315581
 *
 * @author pttrung
 */
public class C {

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] dp = new int[Math.max(100, n + 1)];
        int[] count = new int[10];
        int[][] hold = new int[n + 1][10];
        for (int i = 1; i < 10; i++) {
            dp[i] = i % 9 == 0 ? 9 : i % 9;
            if (i <= n) {
                count[dp[i]]++;
                hold[i][dp[i]]++;
            }

        }

        for (int i = 10; i < dp.length; i++) {
            dp[i] = dp[i / 10 + i % 10];
            if (i <= n) {
                count[dp[i]]++;
                hold[i][dp[i]]++;
            }
        }
        for (int i = n - 1; i > 0; i--) {
            for (int j = 1; j < 10; j++) {
                hold[i][j] += hold[i + 1][j];
            }
        }
       // System.out.println((long)n*n);
        //System.out.println("HE HE");
        long result = 0;
        for (int i = 1; i <= n; i++) {
            if ((long)i * i <= n) {
                for (int j = i; j <= n; j++) {
                    if ((long)i * j <= n) {
                        hold[i][dp[j]]--;
                        if (dp[i * j] == dp[dp[i] * dp[j]]) {
                            if (i == j) {
                                result += count[dp[i * j]] - 1;
                            } else {
                                result += 2 * count[dp[i * j]] - 2;
                            }
                        } else {
                          //  System.out.println("HE HE" + " " + i + " " + j + " " + i*j) ;
                            if (i == j) {
                                result += count[dp[i * j]];
                            } else {
                                result += 2 * count[dp[i * j]];
                            }
                        }
                    } else {
                        for (int k = 0; k < 10; k++) {
                            if (hold[i][k] > 0) {
                                result += 2 * hold[i][k] * count[dp[dp[i] * k]];
                            }
                        }
                        break;
                    }
                }
            } else {
                //System.out.println(i);
                for (int j = 0; j < 10; j++) {
                    if (hold[i][j] > 0) {
                        if (j != dp[i]) {
                            result += 2 * hold[i][j] * count[dp[dp[i] * j]];
                        } else {
                            result += 2 * (hold[i][j] - 1) * count[dp[dp[i] * j]];
                            result += count[dp[dp[i] * j]];
                        }

                    }
                }
                //  result--;
            }
        }
        out.println(result);
//        long test = 0;
//        for(int i = 1; i <= n; i++){
//            for(int j = 1 ; j <= n; j++){
//                for(int k = 1; k <= n; k++){
//                    if(k != i*j && dp[k] == dp[i*j]){
//                        test++;
//                    }else if(dp[i*j] != dp[dp[i]*dp[j]]){
//                        test++;
//                    }
//                }
//            }
//        }
//        out.println(result + " " + test);
        out.close();
    }

    static double distance(Point a, Point b) {
        double total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
        return Math.sqrt(total);
    }

    static class Point {

        int x, y, z;

        public Point(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 5 5
 * 4 5
 * 1 4 8
 * 4 2 4
 * 4 1 3
 * 3 1 9
 * 4 5 4
 * 2 7
 * 2 7
 * 5 1
 * 6 3
 * 3 2
 *
 * @author pttrung
 */
public class C {

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] dp = new int[Math.max(100, n + 1)];
        int[] count = new int[10];
        for (int i = 0; i < 10; i++) {
            dp[i] = i;
             count[dp[i]]++;
        }

        dp[10] = 1;
        for (int i = 11; i < dp.length; i++) {
            dp[i] = dp[i / 10 + i % 10];
            if (i <= n) {
                count[dp[i]]++;
            }
        }

        int result = 0;
        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (i * j <= n) {
                    if (dp[i * j] == dp[dp[i] * dp[j]]) {
                        result += count[dp[i] * dp[j]] - 1;
                    } else {
                        result += count[dp[i] * dp[j]];
                    }
                } else {
                    result += count[dp[dp[i] * dp[j]]];
                }
            }
        }
        out.println(result);
        out.close();
    }

    static double distance(Point a, Point b) {
        double total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
        return Math.sqrt(total);
    }

    static class Point {

        int x, y, z;

        public Point(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 111118315581
 *
 * @author pttrung
 */
public class C {

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] dp = new int[Math.max(100, n + 1)];
        int[] count = new int[10];
        int[][] hold = new int[n + 1][10];
        for (int i = 1; i < 10; i++) {
            dp[i] = i % 9 == 0 ? 9 : i % 9;
            if (i <= n) {
                count[dp[i]]++;
                hold[i][dp[i]]++;
            }

        }

        for (int i = 10; i < dp.length; i++) {
            dp[i] = dp[i / 10 + i % 10];
            if (i <= n) {
                count[dp[i]]++;
                hold[i][dp[i]]++;
            }
        }
        for (int i = n - 1; i > 0; i--) {
            for (int j = 1; j < 10; j++) {
                hold[i][j] += hold[i + 1][j];
            }
        }
        //System.out.println("HE HE");
        long result = 0;
        for (int i = 1; i <= n; i++) {
            if (i * i <= n) {
                for (int j = i; j <= n; j++) {
                    if (i * j <= n && i * j > 0) {
                        hold[i][dp[j]]--;
                        if (dp[i * j] == dp[dp[i] * dp[j]]) {
                            if (i == j) {
                                result += count[dp[i * j]] - 1;
                            } else {
                                result += 2 * count[dp[i * j]] - 2;
                            }
                        }
                    } else {
                        for (int k = 0; k < 10; k++) {
                            if (hold[i][k] > 0) {
                                result += 2 * hold[i][k] * count[dp[dp[i] * k]];
                            }
                        }
                        break;
                    }
                }
            } else {
                //System.out.println(i);
                for (int j = 0; j < 10; j++) {
                    if (hold[i][j] > 0) {
                        result += 2 * hold[i][j] * count[dp[dp[i] * j]];
                    }
                }
            }
        }
        out.println(result);

        out.close();
    }

    static double distance(Point a, Point b) {
        double total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
        return Math.sqrt(total);
    }

    static class Point {

        int x, y, z;

        public Point(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.util.*;
import java.io.*;

/**
 * Created by HREN_VAM.
 */

public class C implements Runnable{

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;
    public static final String filename = "c";

    int n;

    int sq(long n){
        if(n < 10)return (int)n;
        int res = 0;
        while(n != 0){
            res += n % 10;
            n /= 10;
        }
        return sq(res);
    }

    public void solve() throws IOException{
        n = nextInt();
        int[] a = new int[10];
        for(int i = 0;i < n;i ++){
            a[sq(i + 1)] ++;
        }
        long res = 0;
        for(int i = 0;i < 10;i ++){
            for(int j = 0;j < 10;j ++){
                res += (long)a[i] * a[j] * a[sq(i * j)];
            }
        }
        for(int i = 1;i <= n;i ++){
            res -= n / i;
        }
        for(int i = 1;i <= n;i ++){
            int t = sq((long)i * i);
            int ti = sq(i);
            if(a[t] > 0)res -= a[ti] * a[ti] * (a[t] - 1);
        }
        out.println(res);
    }

    public void run(){
        try{
            Locale.setDefault(Locale.US);
            in = new BufferedReader(new InputStreamReader(System.in));
            //in = new BufferedReader(new FileReader(filename + ".in"));
            out = new PrintWriter(System.out);
            //out = new PrintWriter(new FileWriter(filename + ".out"));
            st = new StringTokenizer("");
            solve();
            out.close();
        } catch(IOException e){
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args){
        new Thread(new C()).start();
    }

    public String nextToken() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException{
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }
}

import java.util.*;
import java.io.*;

/**
 * Created by HREN_VAM.
 */

public class C implements Runnable{

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;
    public static final String filename = "c";

    int n;

    int sq(long n){
        if(n < 10)return (int)n;
        int res = 0;
        while(n != 0){
            res += n % 10;
            n /= 10;
        }
        return sq(res);
    }

    public void solve() throws IOException{
        n = nextInt();
        long[] a = new long[10];
        for(int i = 0;i < n;i ++){
            a[sq(i + 1)] ++;
        }
        long res = 0;
        for(int i = 0;i < 10;i ++){
            for(int j = 0;j < 10;j ++){
                res += a[i] * a[j] * a[sq(i * j)];
            }
        }
        for(int i = 1;i <= n;i ++){
            res -= n / i;
        }
        for(long i = 1;i <= n;i ++){
            int t = sq(i * i);
            int ti = sq(i);
            if(a[t] > 0)res -= /*(a[ti] - 1) * (a[ti] - 1) */ (a[t] - 1);
        }
        out.println(res);
    }

    public void run(){
        try{
            Locale.setDefault(Locale.US);
            in = new BufferedReader(new InputStreamReader(System.in));
            //in = new BufferedReader(new FileReader(filename + ".in"));
            out = new PrintWriter(System.out);
            //out = new PrintWriter(new FileWriter(filename + ".out"));
            st = new StringTokenizer("");
            solve();
            out.close();
        } catch(IOException e){
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args){
        new Thread(new C()).start();
    }

    public String nextToken() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException{
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }
}

//package round10;

import java.io.BufferedOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Scanner;

public class C {
	private Scanner in;
	private PrintWriter out;

	public void solve()
	{
		int n = ni();
		long r = 0;
		for(int i = 1;i <= n;i++){
			r += n / i;
		}

		int[] ct = new int[10];
		for(int i = 1;i <= 9;i++){
			ct[i] = n/9 + (i <= n % 9 ? 1 : 0);
		}

		long all = 0;
		for(int a = 1;a <= 9;a++){
			for(int b = 1;b <= 9;b++){
				all += ct[a] * ct[b] * ct[d(a*b)];
//				tr(a, b, d(a*b), all);
			}
		}
		out.println(all - r);
	}

	private int d(int a)
	{
		int m = a%9;
		return m == 0 ? 9 : m;
	}

	public void run() throws Exception
	{
//		in = new Scanner(new StringReader("5"));
		in = new Scanner(System.in);
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		out = new PrintWriter(System.out);

//		int n = in.nextInt();
		int n = 1;
		for(int i = 1;i <= n;i++){
			long t = System.currentTimeMillis();
			solve();
			out.flush();
//			System.err.printf("%04d/%04d %7d%n", i, n, System.currentTimeMillis() - t);
		}
	}

	public static void main(String[] args) throws Exception
	{
		new C().run();
	}

	private int ni() { return Integer.parseInt(in.next()); }
	private static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }
	private void tra(int[] a) {System.out.println(Arrays.toString(a));}
	private void tra(int[][] a)
	{
		for(int[] e : a){
			System.out.println(Arrays.toString(e));
		}
	}

}

import java.util.Scanner;

public class C {
    public static int computeD(int x) {
        int res = 0;
        while (true) {
            while (x > 0) {
                res += (x % 10);
                x /= 10;
            }
            if (res < 10)
                return res;
            x = res;
            res = 0;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n + 1];
        int[] count = new int[10];
        for (int i = 1; i <= n; i++) {
            int tmp = i;
            int res = 0;
            while (tmp > 0) {
                res += tmp % 10;
                tmp /= 10;
            }
            if (res < 10)
                d[i] = res;
            else
                d[i] = d[res];
            count[d[i]]++;
        }
        long res = 0;
        long remove = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                int mul = computeD(i * j);
                long t = count[i] * count[j] * count[mul];
                res += t;
            }
        }
        for (int i = 1; i <= n; i++) {
            long l = 1, h = n, mid;
            while (l < h) {
                mid = l + (h - l) / 2;
                if (mid * i <= n) {
                    l = mid + 1;
                } else {
                    h = mid;
                }
            }
            if (i * l > n)
                l--;
            remove += (l);
        }
        System.out.println(res - remove);
    }
}

import java.util.Scanner;

public class C {
    public static int computeD(int x) {
        int res = 0;
        while (true) {
            while (x > 0) {
                res += (x % 10);
                x /= 10;
            }
            if (res < 10)
                return res;
            x = res;
            res = 0;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n + 1];
        int[] count = new int[10];
        for (int i = 1; i <= n; i++) {
            int tmp = i;
            int res = 0;
            while (tmp > 0) {
                res += tmp % 10;
                tmp /= 10;
            }
            if (res < 10)
                d[i] = res;
            else
                d[i] = d[res];
            count[d[i]]++;
        }
        long res = 0;
        long remove = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                int mul = computeD(i * j);
                long t = count[i] * count[j] * count[mul];
                res += t;
            }
        }
        remove = 0;
        for (int i = 1; i <= n; i++) {
            int l = 1, h = n, mid;
            while (l < h) {
                mid = l + (h - l) / 2;
                if (mid * i <= n) {
                    l = mid + 1;
                } else {
                    h = mid;
                }
            }
            if (i * l > n)
                l--;
            remove += (l);
        }
        System.out.println(res - remove);
    }
}

import java.io.*;
import java.util.*;

public class DigitalRoot
{
	public Scanner in = new Scanner(System.in);
	public PrintStream out = System.out;

	public int N;

	public void main()
	{
		N = in.nextInt();

		int x, y, z;
		long res = 0;

		long A, B, C;
		int a, b;

		for(z=1;z<=9;++z) for(x=1;x<=9;++x) for(y=1;y<=9;++y) if(z == (x*y)%9)
		{
			C = count(9, z);
			A = count(9, x);
			B = count(9, y);

			res += A * B * C;

			for(int k=0; k*9+x <=N;++k)
			{
				a = k*9*9 + 9*x;
				b = k*9*y + x*y;
				res -= count(a, b);
			}
		}

		out.println(res);
	}//end public void main()

	public int count(int a, int b)
	{
		if(N < b) return 0;
		return (N - b)/a + 1;
	}

	public static void main(String[] args)
	{
		(new DigitalRoot()).main();
	}
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Solution {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    int count(int mod, int n) {
        int res = n / 9 + ((n % 9 >= mod) ? 1 : 0);
        return res;
    }

    int sum(int a) {
        int res = 0;
        while (a > 0) {
            res += a % 10;
            a /= 10;
        }
        return res;
    }

    int d(int a) {
        int s = sum(a);
        if (s < 10)
            return s;
        else
            return d(s);
    }

    void solve() throws IOException {
        int n = ni();
        long res = 0;
        for (int i = 1; i < 10; ++i)
            for (int j = 1; j < 10; ++j)
                for (int k = 1; k < 10; ++k)
                    if (d(i * j) == k) {
                        res += count(i, n) * count(j, n) * count(k, n);
                    }
        for (int i = 1; i <= n; ++i) {
            res -= n / i;
        }
        out.println(res);
    }

    public Solution() throws IOException {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    String ns() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

    public static void main(String[] args) throws IOException {
        new Solution();
    }
}

import java.io.BufferedReader;
import static java.lang.Math.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class problemC implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(new problemC()).start();
	}

	long kol(long n, long mod) {
		if(mod == 0) return n / 9;
		else {
			if(n < mod) return 0;
			else {
				long res = n / 9;
				if(n % 9 >= mod) ++res;
				return res;
			}
		}
	}

	void solve() throws IOException {
		long n = nextInt();
		long res = 0;

		for(long a = 0; a < 10; ++a)
			for(long b = 0; b < 10; ++b)
				for(long c = 0; c < 10; ++c) {
					if((a * b) % 9 == c) {
						long ak = kol(n, a);
						long bk = kol(n, b);
						long ck = kol(n, c);
						if( res + ak * bk * ck < 0)
							System.in.read();
						res += ak * bk * ck;

					}
				}
		for(long a = 1; a <= n; ++a)
			res -= n / a;
		System.out.println(res);
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			// in = new BufferedReader(new FileReader(new File("input.txt")));
			out = new PrintWriter(System.out);
			// out = new PrintWriter(new File("output.txt"));
			solve();
			out.flush();
			out.close();
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	String nextLine() throws IOException {
		tok = null;
		return in.readLine();
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
 * 10:25 ~ 10:42
 *
 */
public class Main {
	public static int MOD = 20090711;
	public static void main(String[] argv) {
		FastScanner scan = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();

		int cnt[] = new int[10];
		for(int i = 1; i <= n; ++i){
			cnt[(i - 1) % 9 + 1]++;
		}
		long ret = 0;
		for(int a = 1; a < 10; ++a){
			for(int b = 1; b < 10; ++b){
				ret += (long) cnt[a] * cnt[b] * cnt[(a * b - 1) % 9 + 1];
			}
			ret -= (n / a);
		}
		out.println(ret);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream is) {
			try {
				br = new BufferedReader(new InputStreamReader(is));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					return null;
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.valueOf(next());
		}
	}
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
/**
 * 10:25 ~ 10:42
 *
 */
public class Main {
	public static void main(String[] argv) {
		FastScanner scan = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = scan.nextInt();
		long ret = 0;
		if(n > 9) ret = ((long)n * (long)n - 9L * 9L);

		for(int i = 1; i <= Math.min(9, n); i++){

			for(int j = 1; j <= i; j++){
				//System.out.println(i + " / " + j + " / " + d(i * j) + " / " + (i * j));
				int target = d(i * j);
				if(target > n) continue;
				if(d(d(i) * d(j)) == target){
					if(i * j != target){
						if(i == j) ret++;
						else ret += 2;
					}
				}
			}
		}
		out.println(ret);
		out.close();
	}
	public static int d(int i){
		if(i < 10) return i;
		int ret = 0;
		while(i > 0){
			ret += (i % 10);
			i /= 10;
		}
		return d(ret);
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream is) {
			try {
				br = new BufferedReader(new InputStreamReader(is));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					return null;
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.valueOf(next());
		}
	}
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
/**
 * 10:25 ~ 10:42
 *
 */
public class Main {
	public static void main(String[] argv) {
		FastScanner scan = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = scan.nextInt();
		long ret = 0;
		if(n > 9) ret = ((long)n * (long)n - 9L * 9L);

		for(int i = 1; i <= Math.min(9, n); i++){

			for(int j = 1; j <= i; j++){
				int target = d(i * j);
				if(target > n) continue;
				if(d(d(i) * d(j)) == target){
					if(i * j != d(i * j)){
						if(i == j) ret++;
						else ret += 2;
					}
				}
			}
		}
		out.println(ret);
		out.close();
	}
	public static int d(int i){
		if(i < 10) return i;
		int ret = 0;
		while(i > 0){
			ret += (i % 10);
			i /= 10;
		}
		return ret;
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream is) {
			try {
				br = new BufferedReader(new InputStreamReader(is));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					return null;
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.valueOf(next());
		}
	}
}

import java.io.*;
import java.util.StringTokenizer;

/**
 * CodeForces 10C - Digital Root
 * Created by Darren on 14-10-11.
 */
public class C {
    Reader in = new Reader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        new C().run();
    }

    int n;

    void run() throws IOException {
        n = in.nextInt();
        int[] cnt = new int[10];
        for (int i = 1; i <= (n-1)%9+1; i++)
            cnt[i] = (n+8) / 9;
        for (int i = (n-1)%9+2; i <= 9; i++)
            cnt[i] = n / 9;

        long result = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++)
                result += cnt[i] * cnt[j] * cnt[(i*j-1)%9+1];
        }
        for (int i = 1; i <= n; i++)
            result -= n / i;
        out.println(result);
        out.flush();
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public Reader(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /** get next word */
        String nextToken() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer( reader.readLine() );
            }
            return tokenizer.nextToken();
        }

        String readLine() throws IOException {
            return reader.readLine();
        }

        int nextInt() throws IOException {
            return Integer.parseInt( nextToken() );
        }

        long nextLong() throws IOException {
            return Long.parseLong( nextToken() );
        }

        double nextDouble() throws IOException {
            return Double.parseDouble( nextToken() );
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class DigitalRoot {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws IOException {

		int n = Integer.parseInt(br.readLine());

		/* Problem statement says (i*j == k) => (d(d(i)*d(j)) == d(k)) so we
		 * only need to check whether !(i*j == k) && (d(d(i)*d(j)) == d(k)).
		 * It's computationally cheaper to calculate A: how many times
		 * (d(d(i)*d(j)) == d(k)) is true and discount B: how many times
		 * (i*j == k) is true.
		 */
		pw.println(A(n)-B(n));
	}

	private static int B(int n) {
		int sol = 0;
		for (int i = 1; i <= n; i++) {
			sol += n/i;
		}
		return sol;
	}

	private static long A(int n) {
		long[] cnt = new long[10];
		for (int i = 1; i < cnt.length; i++) {
			cnt[i] = (n+9-i)/9;
		}
		long sol = 0;
		for (int i = 1; i < cnt.length; i++) {
			for (int j = 1; j < cnt.length; j++) {
				for (int k = 1; k < cnt.length; k++) {
					if (i*j%9 == k%9) {
						sol += cnt[i]*cnt[j]*cnt[k];
					}
				}
			}
		}
		return sol;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class DigitalRoot {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(f.readLine());
        int[] a = new int[9];
        for (int i = 0; i < 9; i++)
            a[i] = n/9;
        for (int i = 9*(n/9)+1; i <= n; i++)
            a[i%9]++;
        long sum = 0;
        for (int x = 0; x < 9; x++)
            for (int y = 0; y < 9; y++)
                sum += a[x]*a[y]*a[(x*y)%9];
        for (int x = 1; x <= n; x++)
            sum -= n/x;

        System.out.println(sum);
    }
}

import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

// Solution is at the bottom of code

public class ProblemC_010 implements Runnable{

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	OutputWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args){
		new Thread(null, new ProblemC_010(), "", 128 * (1L << 20)).start();
	}

	/////////////////////////////////////////////////////////////////////

	void init() throws FileNotFoundException{
		Locale.setDefault(Locale.US);

		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new OutputWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new OutputWriter("output.txt");
		}
	}

	////////////////////////////////////////////////////////////////

	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	void debug(Object... objects){
		if (ONLINE_JUDGE){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

	/////////////////////////////////////////////////////////////////////

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			Locale.setDefault(Locale.US);

			init();
			solve();

			out.close();
			time();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	/////////////////////////////////////////////////////////////////////

	String delim = " ";

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}

		return tok.nextToken(delim);
	}

	String readLine() throws IOException{
		return in.readLine();
	}

	/////////////////////////////////////////////////////////////////

	final char NOT_A_SYMBOL = '\0';

	char readChar() throws IOException{
		int intValue = in.read();

		if (intValue == -1){
			return NOT_A_SYMBOL;
		}

		return (char) intValue;
	}

	char[] readCharArray() throws IOException{
		return readLine().toCharArray();
	}

	/////////////////////////////////////////////////////////////////

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException{
		int[] array = new int[size];

		for (int index = 0; index < size; ++index){
			array[index] = readInt();
		}

		return array;
	}

	///////////////////////////////////////////////////////////////////

	long readLong() throws IOException{
		return Long.parseLong(readString());
	}

	long[] readLongArray(int size) throws IOException{
		long[] array = new long[size];

		for (int index = 0; index < size; ++index){
			array[index] = readLong();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}

	double[] readDoubleArray(int size) throws IOException{
		double[] array = new double[size];

		for (int index = 0; index < size; ++index){
			array[index] = readDouble();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	Point readPoint() throws IOException{
		return new Point(readInt(), readInt());
	}

	Point[] readPointArray(int size) throws IOException{
		Point[] array = new Point[size];

		for (int index = 0; index < size; ++index){
			array[index] = readPoint();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
	throws IOException{
		List<Integer>[] graph = new List[vertexNumber];

		for (int index = 0; index < vertexNumber; ++index){
			graph[index] = new ArrayList<Integer>();
		}

		while (edgeNumber-- > 0){
			int from = readInt() - 1;
			int to = readInt() - 1;

			graph[from].add(to);
			graph[to].add(from);
		}

		return graph;
	}

	/////////////////////////////////////////////////////////////////////

	class OutputWriter extends PrintWriter{

		final int DEFAULT_PRECISION = 12;

		int precision;
		String format, formatWithSpace;

		{
			precision = DEFAULT_PRECISION;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		public OutputWriter(OutputStream out) {
			super(out);
		}

		public OutputWriter(String fileName) throws FileNotFoundException {
			super(fileName);
		}

		public int getPrecision() {
			return precision;
		}

		public void setPrecision(int precision) {
			this.precision = precision;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		private String createFormat(int precision){
			return "%." + precision + "f";
		}

		@Override
		public void print(double d){
			printf(format, d);
		}

		public void printWithSpace(double d){
			printf(formatWithSpace, d);
		}

		public void printAll(double...d){
			for (int i = 0; i < d.length - 1; ++i){
				printWithSpace(d[i]);
			}

			print(d[d.length - 1]);
		}

		@Override
		public void println(double d){
			printlnAll(d);
		}

		public void printlnAll(double... d){
			printAll(d);
			println();
		}
	}

	/////////////////////////////////////////////////////////////////////

	int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

	boolean check(int index, int lim){
		return (0 <= index && index < lim);
	}

	/////////////////////////////////////////////////////////////////////

	void solve() throws IOException{
		int n = readInt();

		long[] count = new long[10];
		for (int i = 1; i <= 9; ++i){
			count[i] = count(i, n);
		}

		int[][] d = new int[10][10];
		for (int i = 1; i <= 9; ++i){
			for (int j = 1; j <= 9; ++j){
				d[i][j] = (i * j) % 9;
				if (d[i][j] == 0) d[i][j] = 9;
			}
		}

		long ans = 0;
		for (int a = 1, s = 1; a <= n; ++a, s = (s == 9? 1: s + 1)){
			int k = n / a;

			for (int b = 1; b <= 9; ++b){
				int c = d[s][b];

				ans += count[b] * count[c] - count(b, k);
			}
		}

		out.println(ans);
	}

	long count(int d, int n){
		long res = n / 9;

		int md = (n + 8) % 9 + 1;
		if (md >= d) res++;

		return res;
	}
}