import java.util.*;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();

      long sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      System.out.println(sum);

   }
   
   private static int gcd(int m, int n) {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   }

} 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 sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      System.out.println(sum);

   }
   
   private static int gcd(int m, int n) {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   }

} Main public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();

      long sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      System.out.println(sum);

   } main {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();

      long sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      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 long sum = 0; sum 0 for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      } int j = 1; int j = 1; j 1 j < k + 1 j k + 1 k 1 j++ j++ j {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      } {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      } for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         } int i = 1; int i = 1; i 1 i < k + 1 i k + 1 k 1 i++ i++ i {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         } {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         } for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            } int h = 1; int h = 1; h 1 h < k + 1 h k + 1 k 1 h++ h++ h {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            } {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            } int s = gcd(j, i); s gcd(j, i) gcd j i int t = gcd(s, h); t gcd(s, h) gcd s h sum = sum + t sum sum + t sum t System.out.println(sum) System.out.println System.out System System.out sum String[] args args private static int gcd(int m, int n) {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   } gcd {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   } if (m < n)
         return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if (n == 0)
         return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n int m m int n n public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();

      long sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      System.out.println(sum);

   }
   
   private static int gcd(int m, int n) {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   }

} public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();

      long sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      System.out.println(sum);

   }
   
   private static int gcd(int m, int n) {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   }

} Main
import java.util.*;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();

      long sum = 0;

      for (int j = 1; j < k + 1; j++) {
         for (int i = 1; i < k + 1; i++) {
            for (int h = 1; h < k + 1; h++) {
               int s = gcd(j, i);
               int t = gcd(s, h);
               sum = sum + t;
            }
         }
      }
      System.out.println(sum);

   }
   
   private static int gcd(int m, int n) {
      if (m < n)
         return gcd(n, m);
      if (n == 0)
         return m;
      return gcd(n, m % n);
   }

}
