import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  }

  static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  }

  static int gcd(int a, int b) {
    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();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  } main {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int answer = 0; answer 0 for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    } int a = 1; int a = 1; a 1 a <= k a k a++ a++ a {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    } {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    } for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      } int b = a; int b = a; b a b <= k b k b++ b++ b {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      } {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      } for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        } int c = b; int c = b; c b c <= k c k c++ c++ c {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        } {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        } int gcd = gcd(a, gcd(b, c)); gcd gcd(a, gcd(b, c)) gcd a gcd(b, c) gcd b c if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          } a == b && b == c a == b a b b == c b c {
            answer += gcd;
          } answer += gcd answer gcd if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          } a == b || a == c || b == c a == b || a == c || b == c a == b a b a == c a c b == c b c {
            answer += 3 * gcd;
          } answer += 3 * gcd answer 3 * gcd 3 gcd {
            answer += 6 * gcd;
          } answer += 6 * gcd answer 6 * gcd 6 gcd System.out.println(answer) System.out.println System.out System System.out answer String[] args args static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  } gcd {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  } if (b == 0) {
      return a;
    } b == 0 b 0 {
      return a;
    } 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();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  }

  static int gcd(int a, int b) {
    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();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  }

  static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int answer = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = a; b <= k; b++) {
        for (int c = b; c <= k; c++) {
          int gcd = gcd(a, gcd(b, c));
          if (a == b && b == c) {
            answer += gcd;
          } else if (a == b || a == c || b == c) {
            answer += 3 * gcd;
          } else {
            answer += 6 * gcd;
          }
        }
      }
    }
    System.out.println(answer);
  }

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