import java.util.Scanner;
public class Main{
    public static int gcd(int a,int b,int c){
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static int gcd(int a,int b,int c){
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    }
} Main public static int gcd(int a,int b,int c){
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    } gcd {
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    } int smallest = Math.min(a,Math.min(b, c)); smallest Math.min(a,Math.min(b, c)) Math.min Math a Math.min(b, c) Math.min Math b c for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        } int i = smallest; int i = smallest; i smallest i > 0 i 0 i-- i-- i {
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        } {
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        } if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            } a%i == 0 && b%i == 0 && c%i == 0 a%i == 0 && b%i == 0 && c%i == 0 a%i == 0 a%i a i 0 b%i == 0 b%i b i 0 c%i == 0 c%i c i 0 {
                return i;
            } return i; i return -1; -1 1 int a a int b b int c c public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    } main {
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int number = sc.nextInt(); number sc.nextInt() sc.nextInt sc int total = 0; total 0 for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        } int i = 1; int i = 1; i 1 i < number+1 i number+1 number 1 i++ i++ i {
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        } {
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        } for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            } int j = 1; int j = 1; j 1 j < number+1 j number+1 number 1 j++ j++ j {
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            } {
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            } for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                } int k = 1; int k = 1; k 1 k < number+1 k number+1 number 1 k++ k++ k {
                    total += gcd(i,j,k);
                } {
                    total += gcd(i,j,k);
                } total += gcd(i,j,k) total gcd(i,j,k) gcd i j k System.out.println(total) System.out.println System.out System System.out total String[] args args public class Main{
    public static int gcd(int a,int b,int c){
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    }
} public class Main{
    public static int gcd(int a,int b,int c){
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    }
} Main
import java.util.Scanner;
public class Main{
    public static int gcd(int a,int b,int c){
        int smallest = Math.min(a,Math.min(b, c));
        for(int i = smallest;i > 0;i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int total = 0;
        for(int i = 1;i < number+1;i++){
            for(int j = 1;j < number+1;j++){
                for(int k = 1;k < number+1;k++){
                    total += gcd(i,j,k);
                }
            }
        }
        System.out.println(total);
    }
}