import java.util.*;

public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    }
} import java.util.*; util.* java public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    }
} Main static int gcd (int a, int b) {
        return b == 0 ? a : gcd (b, a % b);
    } gcd {
        return b == 0 ? a : gcd (b, a % b);
    } return b == 0 ? a : gcd (b, a % b); b == 0 ? a : gcd (b, a % b) b == 0 b 0 a gcd (b, a % b) gcd b a % b a b int a a int b b public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    } main {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long total = 0; total 0 int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        } int x = 1; int x = 1; x 1 x < k + 1 x k + 1 k 1 x++ x++ x {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        } {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        } total += x total x for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            } int y = x+1; int y = x+1; y x+1 x 1 y < k + 1 y k + 1 k 1 y++ y++ y {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            } {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            } int first = gcd(x, y); first gcd(x, y) gcd x y total += 2 * 3 * first total 2 * 3 * first 2 * 3 * first 2 3 first for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                } int z = y+1; int z = y+1; z y+1 y 1 z < k + 1 z k + 1 k 1 z++ z++ z {
                    total += 6 * gcd(first, z);
                } {
                    total += 6 * gcd(first, z);
                } total += 6 * gcd(first, z) total 6 * gcd(first, z) 6 gcd(first, z) gcd first z System.out.println(total) System.out.println System.out System System.out total String[] args args public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    }
} public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    }
} Main
import java.util.*;

public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        int k = sc.nextInt();

        for (int x = 1; x < k + 1; x++) {
            total += x;
            for (int y = x+1; y < k + 1; y++) {
                int first = gcd(x, y);
                total += 2 * 3 * first;
                for (int z = y+1; z < k + 1; z++) {
                    total += 6 * gcd(first, z);
                }
            }
        }
        System.out.println(total);
    }
}