import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int a = K;
        int b = K;
        int c = K;
      	int sum = 0;
      
        for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } 
        System.out.println(sum);
    }
  
private static int gcd(int m, int n) {
    while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    }
  	return m;
}
}
 import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int a = K;
        int b = K;
        int c = K;
      	int sum = 0;
      
        for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } 
        System.out.println(sum);
    }
  
private static int gcd(int m, int n) {
    while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    }
  	return m;
}
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int a = K;
        int b = K;
        int c = K;
      	int sum = 0;
      
        for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } 
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int a = K;
        int b = K;
        int c = K;
      	int sum = 0;
      
        for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } 
        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 int a = K; a K int b = K; b K int c = K; c K int sum = 0; sum 0 for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } int A=1; int A=1; A 1 A<=a A a A++ A++ A {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			} int B=1; int B=1; B 1 B<=b B b B++ B++ B {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			} {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			} for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				} int C=1; int C=1; C 1 C<=c C c C++ C++ C {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				} {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				} int t1 = gcd(A,B); t1 gcd(A,B) gcd A B int t2 = gcd(t1,C); t2 gcd(t1,C) gcd t1 C sum += t2 sum t2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args private static int gcd(int m, int n) {
    while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    }
  	return m;
} gcd {
    while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    }
  	return m;
} while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    } n > 0 n 0 {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    } int temp = n; temp n n = m % n n m % n m n m = temp m temp return m; m int m m int n n
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int a = K;
        int b = K;
        int c = K;
      	int sum = 0;
      
        for (int A=1; A<=a; A++) {
			for (int B=1; B<=b; B++) {
				for (int C=1; C<=c; C++) {
					int t1 = gcd(A,B);
                  	int t2 = gcd(t1,C);
                  	sum += t2;
				}
			}
        } 
        System.out.println(sum);
    }
  
private static int gcd(int m, int n) {
    while (n > 0)
    {
        int temp = n;
        n = m % n; // % is remainder
        m = temp;
    }
  	return m;
}
}

