
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    }

    private static int gcd(int a, int b) {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    }

    private static int gcd(int a, int b) {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    }

} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    } main {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int k = Integer.parseInt(scan.next()); k Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan scan.close() scan.close scan int sum = 0; sum 0 for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        } int a = 1; int a = 1; a 1 a <= k a k a++ a++ a {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        } {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        } for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            } int b = 1; int b = 1; b 1 b <= k b k b++ b++ b {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            } {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            } for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                } int c = 1; int c = 1; c 1 c <= k c k c++ c++ c {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                } {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                } int gcd = gcd(a, gcd(b, c)); gcd gcd(a, gcd(b, c)) gcd a gcd(b, c) gcd b c sum += gcd sum gcd System.out.println(sum) System.out.println System.out System System.out sum String[] args args private static int gcd(int a, int b) {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    } gcd {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    } if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        } a < b a b {
            int memory = a;
            a = b;
            b = memory;
        } int memory = a; memory a a = b a b b = memory b memory int q = a % b; q a % b a b while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        } q != 0 q 0 {
            a = b;
            b = q;
            q = a % b;
        } a = b a b b = q b q q = a % b q a % b a b return b; b int a a int b b public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    }

    private static int gcd(int a, int b) {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    }

} public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    }

    private static int gcd(int a, int b) {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    }

} Main

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = Integer.parseInt(scan.next());
        scan.close();

        int sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    int gcd = gcd(a, gcd(b, c));
                    sum += gcd;
                }
            }
        }

        System.out.println(sum);
    }

    private static int gcd(int a, int b) {
        if (a < b) {
            int memory = a;
            a = b;
            b = memory;
        }

        int q = a % b;
        while (q != 0) {
            a = b;
            b = q;
            q = a % b;
        }
        return b;
    }

}
