import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    }

    public static long getDualGcb(long m, long n) {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    }

    public static long getDualGcb(long m, long n) {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc sc.close() sc.close sc long sum = 0; sum 0 for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        } int a = 1; int a = 1; a 1 a <= K a K a++ a++ a {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        } {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        } for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            } int b = 1; int b = 1; b 1 b <= K b K b++ b++ b {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            } {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            } long tmp = getDualGcb(a, b); tmp getDualGcb(a, b) getDualGcb a b for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                } int c = 1; int c = 1; c 1 c <= K c K c++ c++ c {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                } {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                } long tmp2 = getDualGcb(tmp, c); tmp2 getDualGcb(tmp, c) getDualGcb tmp c sum += tmp2 sum tmp2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static long getDualGcb(long m, long n) {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    } getDualGcb {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    } long ret = 0; ret 0 for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        } long i = m; long i = m; i m i >= 1 i 1 i-- i-- i {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        } {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        } if (m % i != 0) {
                continue;
            } m % i != 0 m % i m i 0 {
                continue;
            } continue; if (n >= i && n % i == 0) {
                ret = i;
                break;
            } n >= i && n % i == 0 n >= i n i n % i == 0 n % i n i 0 {
                ret = i;
                break;
            } ret = i ret i break; return ret; ret long m m long n n public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    }

    public static long getDualGcb(long m, long n) {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    }

    public static long getDualGcb(long m, long n) {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        sc.close();

        long sum = 0;
        for (int a = 1; a <= K; a++) {
            for (int b = 1; b <= K; b++) {
                long tmp = getDualGcb(a, b);
                for (int c = 1; c <= K; c++) {
                    long tmp2 = getDualGcb(tmp, c);
                    sum += tmp2;
                }
            }
        }
        System.out.println(sum);
    }

    public static long getDualGcb(long m, long n) {
        long ret = 0;
        for (long i = m; i >= 1; i--) {
            if (m % i != 0) {
                continue;
            }
            if (n >= i && n % i == 0) {
                ret = i;
                break;
            }
        }
        return ret;
    }
}
