import java.util.Scanner;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    }
    public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      }
} import java.util.Scanner; Scanner java.util public class Main {
    static Scanner sc = new Scanner(System.in);
    public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    }
    public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    } gcd {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    } int temp; temp while((temp = a%b)!=0) {
        a = b;
        b = temp;
      } (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
        a = b;
        b = temp;
      } a = b a b b = temp b temp return b; b int a a int b b public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      } main {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      } int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int answer = 0; answer 0 int x = 0; x 0 int y = 0; y 0 for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      } {
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      } for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        } int j = 1; int j = 1; j 1 j <= N j N j++ j++ j {
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        } {
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        } for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          } int k = 1; int k = 1; k 1 k <= N k N k++ k++ k {
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          } {
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          } x = gcd(i,j) x gcd(i,j) gcd i j y = gcd(x,k) y gcd(x,k) gcd x k answer += y answer y System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
    static Scanner sc = new Scanner(System.in);
    public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    }
    public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      }
} public class Main {
    static Scanner sc = new Scanner(System.in);
    public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    }
    public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      }
} Main
import java.util.Scanner;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    }
    public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      }
}