import java.util.*;

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

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

        System.out.println(ret);
    }

    private static int gcd(int n, int m) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} import java.util.*; util.* java public class Main {
    static public void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt(), ret = 0;

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

        System.out.println(ret);
    }

    private static int gcd(int n, int m) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} Main static public void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt(), ret = 0;

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

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

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

        System.out.println(ret);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt() k sc.nextInt() sc.nextInt sc ret = 0; ret 0 for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int h = 1; h <= k; h++) {
                    ret += 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++) {
                    ret += gcd(i, gcd(j, h));
                }
            }
        } {
            for (int j = 1; j <= k; j++) {
                for (int h = 1; h <= k; h++) {
                    ret += gcd(i, gcd(j, h));
                }
            }
        } for (int j = 1; j <= k; j++) {
                for (int h = 1; h <= k; h++) {
                    ret += 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++) {
                    ret += gcd(i, gcd(j, h));
                }
            } {
                for (int h = 1; h <= k; h++) {
                    ret += gcd(i, gcd(j, h));
                }
            } for (int h = 1; h <= k; h++) {
                    ret += gcd(i, gcd(j, h));
                } int h = 1; int h = 1; h 1 h <= k h k h++ h++ h {
                    ret += gcd(i, gcd(j, h));
                } {
                    ret += gcd(i, gcd(j, h));
                } ret += gcd(i, gcd(j, h)) ret gcd(i, gcd(j, h)) gcd i gcd(j, h) gcd j h System.out.println(ret) System.out.println System.out System System.out ret String args[] args private static int gcd(int n, int m) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    } gcd {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    } int r; r while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        } n > 0 n 0 {
            r = m % n;
            m = n;
            n = r;
        } r = m % n r m % n m n m = n m n n = r n r return m; m int n n int m m public class Main {
    static public void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt(), ret = 0;

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

        System.out.println(ret);
    }

    private static int gcd(int n, int m) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} public class Main {
    static public void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt(), ret = 0;

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

        System.out.println(ret);
    }

    private static int gcd(int n, int m) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} Main
import java.util.*;

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

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

        System.out.println(ret);
    }

    private static int gcd(int n, int m) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
}