import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  }

  static int gcd(int a, int b) { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  }

  static int gcd(int a, int b) { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc long res = 0; res 0 for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    } {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    } for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      } int j = i; int j = i; j i j <= k j k j++ j++ j {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      } {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      } for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        } int l = j; int l = j; l j l <= k l k l++ l++ l {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        } {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        } if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          } i < j && j < l i < j i j j < l j l {
            res += gcd(i, gcd(j, l)) * 6;
          } res += gcd(i, gcd(j, l)) * 6 res gcd(i, gcd(j, l)) * 6 gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l 6 if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          } i < j && j == l i < j i j j == l j l {
            res += gcd(i, gcd(j, l)) * 3;
          } res += gcd(i, gcd(j, l)) * 3 res gcd(i, gcd(j, l)) * 3 gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l 3 if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          } i == j && j < l i == j i j j < l j l {
            res += gcd(i, gcd(j, l)) * 3;
          } res += gcd(i, gcd(j, l)) * 3 res gcd(i, gcd(j, l)) * 3 gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l 3 {
            res += gcd(i, gcd(j, l));
          } res += gcd(i, gcd(j, l)) res gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l System.out.println(res) System.out.println System.out System System.out res sc.close() sc.close sc String[] args args static int gcd(int a, int b) { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  } gcd { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  } if (a < b) return gcd (b, a); a < b a b return gcd (b, a); gcd (b, a) gcd b a if (b == 0) return a; b == 0 b 0 return a; a return gcd (b, a % b); gcd (b, a % b) gcd b a % b a b int a a int b b public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  }

  static int gcd(int a, int b) { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  }

  static int gcd(int a, int b) { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long res = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        for (int l = j; l <= k; l++) {
          if (i < j && j < l) {
            res += gcd(i, gcd(j, l)) * 6;
          } else if (i < j && j == l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else if (i == j && j < l) {
            res += gcd(i, gcd(j, l)) * 3;
          } else {
            res += gcd(i, gcd(j, l));
          }
        }
      }
    }
    System.out.println(res);
    sc.close();
  }

  static int gcd(int a, int b) { // 最大公約数を返す
    if (a < b) return gcd (b, a);
    if (b == 0) return a;
    return gcd (b, a % b);
  }
}