import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) C solver = new C(); solver new C() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    } C public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        } solve {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        } int k = Integer.parseInt(in.next()); k Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in long ans = 0; ans 0 for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            } {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            } for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                } {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                } for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    } int l = 1; int l = 1; l 1 l <= k l k l++ l++ l {
                        ans += gcd(i, gcd(j, l));
                    } {
                        ans += gcd(i, gcd(j, l));
                    } ans += gcd(i, gcd(j, l)) ans gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l out.println(ans) out.println out ans int testNumber testNumber Scanner in in PrintWriter out out public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        } gcd {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        } if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2); num2 == 0 num2 0 return num1; num1 return gcd(num2, num1 % num2); gcd(num2, num1 % num2) gcd num2 num1 % num2 num1 num2 int num1 num1 int num2 num2 public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        ans += gcd(i, gcd(j, l));
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
}

