import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

        System.out.println(out);
        sc.close();
    }
    static int gcd(int a, int b){
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

        System.out.println(out);
        sc.close();
    }
    static int gcd(int a, int b){
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

        System.out.println(out);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

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

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

        System.out.println(out);
        sc.close();
    }
    static int gcd(int a, int b){
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

        System.out.println(out);
        sc.close();
    }
    static int gcd(int a, int b){
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        int out = 0;
        for(int i = 1; i < k + 1; i++){
            for(int j = 1; j < k + 1; j++){
                for(int h = 1; h < k + 1; h++){
                    out += gcd(i, gcd(j, h));
                }
            }
        }

        System.out.println(out);
        sc.close();
    }
    static int gcd(int a, int b){
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
}