import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    }

    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    }

    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} Main public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    } main {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int K = scanner.nextInt(); K scanner.nextInt() scanner.nextInt scanner int[][] gmap = new int[K][K]; gmap new int[K][K] K K for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        } int i = 0; int i = 0; i 0 i < K i K i++ i++ i {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        } {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        } for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            } int j = 0; int j = 0; j 0 j < K j K j++ j++ j {
                gmap[i][j] = gcd(i + 1, j + 1);
            } {
                gmap[i][j] = gcd(i + 1, j + 1);
            } gmap[i][j] = gcd(i + 1, j + 1) gmap[i][j] gmap[i] gmap i j gcd(i + 1, j + 1) gcd i + 1 i 1 j + 1 j 1 int[] rightGcdMap = new int[K]; rightGcdMap new int[K] K for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        } int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        } {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        } for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            } int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            } {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            } int gcd = gcd(i, j); gcd gcd(i, j) gcd i j rightGcdMap[gcd - 1]++ rightGcdMap[gcd - 1] rightGcdMap gcd - 1 gcd 1 int[] leftGcdMap = new int[K]; leftGcdMap new int[K] K for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        } int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        } {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        } for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            } int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            } {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            } int gcd = gcd(i, j); gcd gcd(i, j) gcd i j leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1] leftGcdMap[gcd - 1] leftGcdMap gcd - 1 gcd 1 gcd(i, j) * rightGcdMap[j - 1] gcd(i, j) gcd i j rightGcdMap[j - 1] rightGcdMap j - 1 j 1 System.out.println(Arrays.stream(leftGcdMap).sum()) System.out.println System.out System System.out Arrays.stream(leftGcdMap).sum() Arrays.stream(leftGcdMap).sum Arrays.stream(leftGcdMap) Arrays.stream Arrays leftGcdMap String... args args private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n int m m int n n public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    }

    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    }

    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();

        // K * Kの最大公約数を出しておくマップ
        int[][] gmap = new int[K][K];

        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                gmap[i][j] = gcd(i + 1, j + 1);
            }
        }

        // GCD, 個数
        int[] rightGcdMap = new int[K];

        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                rightGcdMap[gcd - 1]++;
            }
        }

        int[] leftGcdMap = new int[K];
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                int gcd = gcd(i, j);

                leftGcdMap[gcd - 1] += gcd(i, j) * rightGcdMap[j - 1];
            }
        }


        System.out.println(Arrays.stream(leftGcdMap).sum());
    }

    private static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}
