import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    }
  static int gcd3(int a , int b , int c){
    return gcd2(gcd2(a,b),c);
  }
      
  static int gcd2(int a, int b){
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    }
  static int gcd3(int a , int b , int c){
    return gcd2(gcd2(a,b),c);
  }
      
  static int gcd2(int a, int b){
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  }
} Main public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    } main {
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      } int A = 1 ; int A = 1 ; A 1 A < a + 1 A a + 1 a 1 A++ A++ A {
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      } {
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      } for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        } int B = 1 ; int B = 1 ; B 1 B < a + 1 B a + 1 a 1 B++ B++ B {
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        } {
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        } for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          } int C = 1 ; int C = 1 ; C 1 C < a + 1 C a + 1 a 1 C++ C++ C {
            sum += gcd3(A,B,C);
          } {
            sum += gcd3(A,B,C);
          } sum += gcd3(A,B,C) sum gcd3(A,B,C) gcd3 A B C System.out.println(sum) System.out.println System.out System System.out sum String[] args args static int gcd3(int a , int b , int c){
    return gcd2(gcd2(a,b),c);
  } gcd3 {
    return gcd2(gcd2(a,b),c);
  } return gcd2(gcd2(a,b),c); gcd2(gcd2(a,b),c) gcd2 gcd2(a,b) gcd2 a b c int a a int b b int c c static int gcd2(int a, int b){
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  } gcd2 {
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  } if(a % b == 0)
      return b; a % b == 0 a % b a b 0 return b; b return gcd2(b , a % b); gcd2(b , a % b) gcd2 b a % b a b int a a int b b public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    }
  static int gcd3(int a , int b , int c){
    return gcd2(gcd2(a,b),c);
  }
      
  static int gcd2(int a, int b){
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  }
} public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    }
  static int gcd3(int a , int b , int c){
    return gcd2(gcd2(a,b),c);
  }
      
  static int gcd2(int a, int b){
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int sum = 0;
      for(int A = 1 ; A < a + 1 ; A++){
        for(int B = 1 ; B < a + 1 ; B++){
          for(int C = 1 ; C < a + 1 ; C++){
            sum += gcd3(A,B,C);
          }
        }
      }
      System.out.println(sum);
    }
  static int gcd3(int a , int b , int c){
    return gcd2(gcd2(a,b),c);
  }
      
  static int gcd2(int a, int b){
    if(a % b == 0)
      return b;
    return gcd2(b , a % b);
  }
}
