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
 *
 * @author silviase
 */
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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        }

    }

    static class Arith {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    }
}
 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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        }

    }

    static class Arith {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    }
} 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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        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) CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy(); solver new CSumOfGcdOfTuplesEasy() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        }

    } CSumOfGcdOfTuplesEasy public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        } solve {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        } int k = in.nextInt(); k in.nextInt() in.nextInt in long sum = 0; sum 0 for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.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++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            } {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            } for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.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++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                } {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                } for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    } int l = 1; int l = 1; l 1 l <= k l k l++ l++ l {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    } {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    } sum += Arith.gcd(i, Arith.gcd(j, l)) sum Arith.gcd(i, Arith.gcd(j, l)) Arith.gcd Arith i Arith.gcd(j, l) Arith.gcd Arith j l out.println(sum) out.println out sum int testNumber testNumber Scanner in in PrintWriter out out static class Arith {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    } Arith public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        } gcd {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        } if (b == 0) return a; b == 0 b 0 return a; a return a % b == 0 ? b : gcd(b, a % b); a % b == 0 ? b : gcd(b, a % b) a % b == 0 a % b a b 0 b gcd(b, a % b) gcd b a % b a b long a a long b b 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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        }

    }

    static class Arith {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    }
} 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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        }

    }

    static class Arith {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    }
} 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
 *
 * @author silviase
 */
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);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        sum += Arith.gcd(i, Arith.gcd(j, l));
                    }
                }
            }
            out.println(sum);
        }

    }

    static class Arith {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    }
}

