import java.util.*;

public class Main {
  private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  }
  
  private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  }
}
 import java.util.*; util.* java public class Main {
  private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  }
  
  private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  }
} Main private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  } gcd {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  } if(p % q == 0)return q; p % q == 0 p % q p q 0 return q; q return gcd(q, p % q); gcd(q, p % q) gcd q p % q p q int p p int q q private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  } solve {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  } long result = 0; result 0 for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(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++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    } {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    } for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(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++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      } {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      } for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        } int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        } {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        } if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          } i == j && j == k i == j i j j == k j k {
            result += i;
          } result += i result i {
            result += gcd(gcd(i, j), k);
          } result += gcd(gcd(i, j), k) result gcd(gcd(i, j), k) gcd gcd(i, j) gcd i j k return result; result int n n public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) System.out.println(solve(sc.nextInt())) System.out.println System.out System System.out solve(sc.nextInt()) solve sc.nextInt() sc.nextInt sc sc.close() sc.close sc String[] args args public class Main {
  private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  }
  
  private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  }
} public class Main {
  private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  }
  
  private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  }
} Main
import java.util.*;

public class Main {
  private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  }
  
  private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  }
}

