import java.util.Scanner;

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

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