import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    }
    public static int gcd(int a, int b){
        if(a == 0) return b;
        return gcd(b%a, a);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    }
    public static int gcd(int a, int b){
        if(a == 0) return b;
        return gcd(b%a, a);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} Main public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    } main {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    } FastScanner fs = new FastScanner(); fs new FastScanner() int k = fs.nextInt(); k fs.nextInt() fs.nextInt fs long ans = 0; ans 0 for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        } int i=1; int i=1; i 1 i<=k i k ++i ++i i {
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        } {
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        } for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            } int j=1; int j=1; j 1 j<=k j k ++j ++j j {
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            } {
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            } for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                } int h=1; int h=1; h 1 h<=k h k ++h ++h h {
                    ans += gcd(i,gcd(j,h));
                } {
                    ans += gcd(i,gcd(j,h));
                } ans += gcd(i,gcd(j,h)) ans gcd(i,gcd(j,h)) gcd i gcd(j,h) gcd j h System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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 static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    } FastScanner BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(""); st new StringTokenizer("") String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        } next {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        } while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        } readArray {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        } int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) a[i] = nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = nextInt(); a[i] = nextInt() a[i] a i nextInt() nextInt return a; a int n n long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    }
    public static int gcd(int a, int b){
        if(a == 0) return b;
        return gcd(b%a, a);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    }
    public static int gcd(int a, int b){
        if(a == 0) return b;
        return gcd(b%a, a);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int k = fs.nextInt();
        long ans = 0;
        for(int i=1; i<=k; ++i){
            for(int j=1; j<=k; ++j){
                for(int h=1; h<=k; ++h){
                    ans += gcd(i,gcd(j,h));
                }
            }
        }
        System.out.println(ans);
    }
    public static int gcd(int a, int b){
        if(a == 0) return b;
        return gcd(b%a, a);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}
