import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  }

  public static int find(int a,int b,int c){
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  }

} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  }

  public static int find(int a,int b,int c){
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  }

} Main public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  } main {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int sum = 0; sum 0 for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    } 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++){
          sum += find(i,j,k);
        }
      }
    } {
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    } for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      } int j=1; int j=1; j 1 j<=n j n j++ j++ j {
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      } {
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      } for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        } int k=1; int k=1; k 1 k<=n k n k++ k++ k {
          sum += find(i,j,k);
        } {
          sum += find(i,j,k);
        } sum += find(i,j,k) sum find(i,j,k) find i j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int find(int a,int b,int c){
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  } find {
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  } int min = a; min a if (a>b){
      min = b;
    } a>b a b {
      min = b;
    } min = b min b if (min>c){
      min = c;
    } min>c min c {
      min = c;
    } min = c min c int l = min; l min while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    } l>1 l 1 {
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    } if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      } (a%l == 0) && (b%l == 0) && (c%l == 0) (a%l == 0) && (b%l == 0) && (c%l == 0) (a%l == 0) a%l a l 0 (b%l == 0) b%l b l 0 (c%l == 0) c%l c l 0 {
        return l;
      } return l; l l -= 1 l 1 return l; l int a a int b b int c c public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  }

  public static int find(int a,int b,int c){
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  }

} public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  }

  public static int find(int a,int b,int c){
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  }

} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    for (int i=1;i<=n;i++){
      for (int j=1;j<=n;j++){
        for (int k=1;k<=n;k++){
          sum += find(i,j,k);
        }
      }
    }
    System.out.println(sum);
  }

  public static int find(int a,int b,int c){
    int min = a;
    if (a>b){
      min = b;
    }
    if (min>c){
      min = c;
    }

    int l = min;
    while (l>1){
      if ((a%l == 0) && (b%l == 0) && (c%l == 0)){
        return l;
      }
      l -= 1;
    }
    return l;
  }

}
