import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	}

	public static int gcd2(int x, int y) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

	public static int gcd3(int x, int y, int z) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	}

	public static int gcd2(int x, int y) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

	public static int gcd3(int x, int y, int z) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	} main {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int K = scan.nextInt(); K scan.nextInt() scan.nextInt scan int num1 = 0; num1 0 int num2 = 0; num2 0 int num3 = 0; num3 0 int ans = 0; ans 0 num1 = K*(K+1) / 2 num1 K*(K+1) / 2 K*(K+1) K (K+1) K 1 2 for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		} int a = 1; int a = 1; a 1 a < K a K a++ a++ a {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		} {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		} for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			} int b = a+1; int b = a+1; b a+1 a 1 b < K+1 b K+1 K 1 b++ b++ b {
				num2 += gcd2(a, b);
			} {
				num2 += gcd2(a, b);
			} num2 += gcd2(a, b) num2 gcd2(a, b) gcd2 a b for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		} int a = 1; int a = 1; a 1 a < K-1 a K-1 K 1 a++ a++ a {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		} {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		} for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			} int b = a+1; int b = a+1; b a+1 a 1 b < K b K b++ b++ b {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			} {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			} for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				} int c = b+1; int c = b+1; c b+1 b 1 c < K+1 c K+1 K 1 c++ c++ c {
					num3 += gcd3(a, b, c);
				} {
					num3 += gcd3(a, b, c);
				} num3 += gcd3(a, b, c) num3 gcd3(a, b, c) gcd3 a b c ans = num1 + num2*6 + num3*6 ans num1 + num2*6 + num3*6 num1 + num2*6 + num3*6 num1 num2*6 num2 6 num3*6 num3 6 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static int gcd2(int x, int y) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	} gcd2 {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	} int i = x; i x while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		} i > 1 i 1 {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		} if (x%i == 0 && y%i == 0) {
				break;
			} x%i == 0 && y%i == 0 x%i == 0 x%i x i 0 y%i == 0 y%i y i 0 {
				break;
			} break; i-- i return i; i int x x int y y public static int gcd3(int x, int y, int z) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	} gcd3 {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	} int i = x; i x while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		} i > 1 i 1 {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		} if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			} x%i == 0 && y%i == 0 && z%i == 0 x%i == 0 && y%i == 0 && z%i == 0 x%i == 0 x%i x i 0 y%i == 0 y%i y i 0 z%i == 0 z%i z i 0 {
				break;
			} break; i-- i return i; i int x x int y y int z z public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	}

	public static int gcd2(int x, int y) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

	public static int gcd3(int x, int y, int z) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	}

	public static int gcd2(int x, int y) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

	public static int gcd3(int x, int y, int z) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int ans = 0;

//a,b,cがすべて等しい．
		num1 = K*(K+1) / 2;

//a,b,cのうち2つが等しい．
		for (int a = 1; a < K; a++) {
			for (int b = a+1; b < K+1; b++) {
				num2 += gcd2(a, b);
			}
		}


//a,b,cがすべて異なる．
		for (int a = 1; a < K-1; a++) {
			for (int b = a+1; b < K; b++) {
				for (int c = b+1; c < K+1; c++) {
					num3 += gcd3(a, b, c);
				}
			}
		}

		ans = num1 + num2*6 + num3*6;

		System.out.println(ans);
	}

	public static int gcd2(int x, int y) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

	public static int gcd3(int x, int y, int z) {
		int i = x;

		while (i > 1) {
			if (x%i == 0 && y%i == 0 && z%i == 0) {
				break;
			}
			i--;
		}

		return i;
	}

}