import java.util.Scanner;

public class Main {

    public static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    }
} Main public static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    } gcd {
        if (b == 0) return a;
        return gcd(b, a % b);
    } if (b == 0) return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b int a a int b b public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long sum = 0; sum 0 for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        } int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        } {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        } for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            } int j = 1; int j = 1; j 1 j < n + 1 j n + 1 n 1 j++ j++ j {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            } {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            } for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                } int k = 1; int k = 1; k 1 k < n + 1 k n + 1 n 1 k++ k++ k {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                } {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                } int a = gcd(j, k); a gcd(j, k) gcd j k int b = gcd(i, a); b gcd(i, a) gcd i a sum += b sum b System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {

    public static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    }
} public class Main {

    public static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    }
} Main
import java.util.Scanner;

public class Main {

    public static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < n + 1; j++) {
                for (int k = 1; k < n + 1; k++) {
                    int a = gcd(j, k);
                    int b = gcd(i, a);
                    sum += b;
                }
            }
        }
        System.out.println(sum);

    }
}
