import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

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

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

        System.out.println(sum);
    }

    public static int gcd(int num1, int num2) {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    }
} import java.io.File; File java.io import java.io.FileInputStream; FileInputStream java.io import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int sum = 0;

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

        System.out.println(sum);
    }

    public static int gcd(int num1, int num2) {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int sum = 0;

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

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

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

        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 int sum = 0; sum 0 for (int i=1; i<=k; i++) {
            for (int j=1; j<=k; j++) {
                for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                }
            }
        } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
            for (int j=1; j<=k; j++) {
                for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                }
            }
        } {
            for (int j=1; j<=k; j++) {
                for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                }
            }
        } for (int j=1; j<=k; j++) {
                for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                }
            } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
                for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                }
            } {
                for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                }
            } for (int l=1; l<=k; l++) {
                    sum += gcd(gcd(i, j), l);
                } int l=1; int l=1; l 1 l<=k l k l++ l++ l {
                    sum += gcd(gcd(i, j), l);
                } {
                    sum += gcd(gcd(i, j), l);
                } sum += gcd(gcd(i, j), l) sum gcd(gcd(i, j), l) gcd gcd(i, j) gcd i j l System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int num1, int num2) {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    } gcd {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    } if (num2 == 0) return num1; num2 == 0 num2 0 return num1; num1 return gcd(num2, num1 % num2); gcd(num2, num1 % num2) gcd num2 num1 % num2 num1 num2 int num1 num1 int num2 num2 public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int sum = 0;

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

        System.out.println(sum);
    }

    public static int gcd(int num1, int num2) {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int sum = 0;

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

        System.out.println(sum);
    }

    public static int gcd(int num1, int num2) {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    }
} Main
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

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

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

        System.out.println(sum);
    }

    public static int gcd(int num1, int num2) {
        if (num2 == 0) return num1;
        return gcd(num2, num1 % num2);
    }
}
