import java.util.*;

class Main {

    static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        long res = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        }

        System.out.println(res);
        sc.close();
    }
} import java.util.*; util.* java class Main {

    static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        long res = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        }

        System.out.println(res);
        sc.close();
    }
} Main static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    } gcd {
        return b > 0 ? gcd(b, a % b) : a;
    } return b > 0 ? gcd(b, a % b) : a; b > 0 ? gcd(b, a % b) : a b > 0 b 0 gcd(b, a % b) gcd b a % b a b a int a a int b b static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    } lcm {
        return a * b / gcd(a, b);
    } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b int a a int b b public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        long res = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        }

        System.out.println(res);
        sc.close();
    } main {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        long res = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        }

        System.out.println(res);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc long res = 0; res 0 for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        } {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        } for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            } {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            } for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                } int l = 1; int l = 1; l 1 l <= k l k l++ l++ l {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                } {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                } res += gcd(i, gcd(j, l)) res gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l System.out.println(res) System.out.println System.out System System.out res sc.close() sc.close sc String[] args args
import java.util.*;

class Main {

    static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        long res = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                    // System.out.println("i:" + i + ",j:" + j + ",l:" + l + "," + res);
                }
            }
        }

        System.out.println(res);
        sc.close();
    }
}
