import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    }

    static int gcd (int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
} import java.text.DecimalFormat; DecimalFormat java.text import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    }

    static int gcd (int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner double sum = 0; sum 0 for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        } int i = 1; int i = 1; i 1 i <= n i n ++i ++i i {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        } {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        } for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            } int j = 1; int j = 1; j 1 j <= n j n ++j ++j j {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            } {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            } for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                } int k = 1; int k = 1; k 1 k <= n k n ++k ++k k {
                    sum += gcd(i, gcd(j, k));
                } {
                    sum += gcd(i, gcd(j, k));
                } sum += gcd(i, gcd(j, k)) sum gcd(i, gcd(j, k)) gcd i gcd(j, k) gcd j k DecimalFormat ft = new DecimalFormat("####"); ft new DecimalFormat("####") System.out.print(ft.format(sum)) System.out.print System.out System System.out ft.format(sum) ft.format ft sum String[] args args 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 public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    }

    static int gcd (int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    }

    static int gcd (int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
} Main
import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double sum = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        DecimalFormat ft = new DecimalFormat("####");
        System.out.print(ft.format(sum));
    }

    static int gcd (int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
}
