import java.util.Scanner;
import java.util.Arrays;
class Main {
  public static long GCD(long x,long y){
    if (y == 0){return x;
    } else{
       return GCD(y, x % y);
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Sum=0;
    long temp=0;
      for(long a=1;a<=N;a++){
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      }





    System.out.println(Sum);

  }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util class Main {
  public static long GCD(long x,long y){
    if (y == 0){return x;
    } else{
       return GCD(y, x % y);
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Sum=0;
    long temp=0;
      for(long a=1;a<=N;a++){
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      }





    System.out.println(Sum);

  }
} Main public static long GCD(long x,long y){
    if (y == 0){return x;
    } else{
       return GCD(y, x % y);
    }
  } GCD {
    if (y == 0){return x;
    } else{
       return GCD(y, x % y);
    }
  } if (y == 0){return x;
    } else{
       return GCD(y, x % y);
    } y == 0 y 0 {return x;
    } return x; x {
       return GCD(y, x % y);
    } return GCD(y, x % y); GCD(y, x % y) GCD y x % y x y long x x long y y public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Sum=0;
    long temp=0;
      for(long a=1;a<=N;a++){
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      }





    System.out.println(Sum);

  } main {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Sum=0;
    long temp=0;
      for(long a=1;a<=N;a++){
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      }





    System.out.println(Sum);

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N=sc.nextLong(); N sc.nextLong() sc.nextLong sc long Sum=0; Sum 0 long temp=0; temp 0 for(long a=1;a<=N;a++){
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      } long a=1; long a=1; a 1 a<=N a N a++ a++ a {
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      } {
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      } for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        } long b=1; long b=1; b 1 b<=N b N b++ b++ b {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        } {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        } for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          } long c=1; long c=1; c 1 c<=N c N c++ c++ c {

            Sum+=GCD(GCD(a,b),c);
          } {

            Sum+=GCD(GCD(a,b),c);
          } Sum+=GCD(GCD(a,b),c) Sum GCD(GCD(a,b),c) GCD GCD(a,b) GCD a b c System.out.println(Sum) System.out.println System.out System System.out Sum String[] args args
import java.util.Scanner;
import java.util.Arrays;
class Main {
  public static long GCD(long x,long y){
    if (y == 0){return x;
    } else{
       return GCD(y, x % y);
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Sum=0;
    long temp=0;
      for(long a=1;a<=N;a++){
        for (long b=1;b<=N ;b++) {
           for(long c=1;c<=N;c++){

            Sum+=GCD(GCD(a,b),c);
          }
        }
      }





    System.out.println(Sum);

  }
}
