import java.util.Scanner;

public class Main {

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

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            }

          } import java.util.Scanner; Scanner java.util public class Main {

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

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            }

          } Main private static int gcd(int a,int b){
      if((a%b)==0) return b;
      return gcd(b,a%b);
    } gcd {
      if((a%b)==0) return b;
      return gcd(b,a%b);
    } if((a%b)==0) return b; (a%b)==0 (a%b) a b 0 return b; b return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b int a a int b b public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            } main {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int tmp; tmp int count = 0; count 0 for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              } int i=1; int i=1; i 1 i<a+1 i a+1 a 1 i++ i++ i {
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              } {
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              } for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                } int j=1; int j=1; j 1 j<a+1 j a+1 a 1 j++ j++ j {
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                } {
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                } tmp = gcd(i,j) tmp gcd(i,j) gcd i j for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  } int k=1; int k=1; k 1 k<a+1 k a+1 a 1 k++ k++ k {
                  count += gcd(k,tmp);
                  } {
                  count += gcd(k,tmp);
                  } count += gcd(k,tmp) count gcd(k,tmp) gcd k tmp System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

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

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            }

          } public class Main {

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

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            }

          } Main
import java.util.Scanner;

public class Main {

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

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            }

          }
