import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	}
  
  	 private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	}
  
  	 private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int max = sc.nextInt(); max sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      } int a=1; int a=1; a 1 a<=max a max a++ a++ a {
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      } {
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      } for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        } int b=1; int b=1; b 1 b<=max b max b++ b++ b {
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        } {
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        } for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          } int c=1; int c=1; c 1 c<=max c max c++ c++ c {
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          } {
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          } int tmp = gcd(b,c); tmp gcd(b,c) gcd b c sum += gcd(a,tmp) sum gcd(a,tmp) gcd a tmp System.out.println(sum) System.out.println System.out System System.out sum String[] args args private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    } gcd {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    } int tmp; tmp while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        } (tmp = x % y) != 0 (tmp = x % y) tmp x % y x y 0 {
            x = y;
            y = tmp;
        } x = y x y y = tmp y tmp return y; y int x x int y y public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	}
  
  	 private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    }
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	}
  
  	 private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	}
  
  	 private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    }
}