import java.util.Scanner;
import java.util.Arrays;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    int sum = 0;
    int[] list = {0,0,0};
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    }

    System.out.println(sum);
  }

  public static int gcd(int[] list) {
    if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    }
  }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    int sum = 0;
    int[] list = {0,0,0};
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    }

    System.out.println(sum);
  }

  public static int gcd(int[] list) {
    if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    }
  }
} Main public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    int sum = 0;
    int[] list = {0,0,0};
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    }

    System.out.println(sum);
  } main {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    int sum = 0;
    int[] list = {0,0,0};
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    }

    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 sc.close() sc.close sc int sum = 0; sum 0 int[] list = {0,0,0}; list {0,0,0} 0 0 0 for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    } {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    } for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      } {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      } for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        } int j2 = 1; int j2 = 1; j2 1 j2 <= k j2 k j2++ j2++ j2 {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        } {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        } list[0] = i list[0] list 0 i list[1] = j list[1] list 1 j list[2] = j2 list[2] list 2 j2 Arrays.sort(list) Arrays.sort Arrays list sum += gcd(list) sum gcd(list) gcd list System.out.println(sum) System.out.println System.out System System.out sum String args[] args public static int gcd(int[] list) {
    if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    }
  } gcd {
    if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    }
  } if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    } list[1]%list[0] == 0 && list[2]%list[0] == 0 list[1]%list[0] == 0 list[1]%list[0] list[1] list 1 list[0] list 0 0 list[2]%list[0] == 0 list[2]%list[0] list[2] list 2 list[0] list 0 0 {
      return list[0];
    } return list[0]; list[0] list 0 {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    } for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      } int i = list[0]/2; int i = list[0]/2; i list[0]/2 list[0] list 0 2 i > 0 i 0 i-- i-- i {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      } {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      } if (list[0]%i != 0) continue; list[0]%i != 0 list[0]%i list[0] list 0 i 0 continue; if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        } list[1]%i == 0 && list[2]%i == 0 list[1]%i == 0 list[1]%i list[1] list 1 i 0 list[2]%i == 0 list[2]%i list[2] list 2 i 0 {
          return i;
        } return i; i return 1; 1 int[] list list
import java.util.Scanner;
import java.util.Arrays;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    int sum = 0;
    int[] list = {0,0,0};
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    }

    System.out.println(sum);
  }

  public static int gcd(int[] list) {
    if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    }
  }
}