import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
} Main public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	} main {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	} int k = 0; k 0 long ans = 0; ans 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) k = sc.nextInt() k sc.nextInt() sc.nextInt sc sc.close() sc.close sc for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		} int i = 1; int i = 1; i 1 i < k + 1 i k + 1 k 1 i++ i++ i {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		} {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		} for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			} int j = 1; int j = 1; j 1 j < k + 1 j k + 1 k 1 j++ j++ j {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			} {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			} for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				} int m = 1; int m = 1; m 1 m < k + 1 m k + 1 k 1 m++ m++ m {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				} {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				} if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					} i == 1 || j == 1 || m == 1 i == 1 || j == 1 || m == 1 i == 1 i 1 j == 1 j 1 m == 1 m 1 {
						ans += 1;
					} ans += 1 ans 1 if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					} i == j && j == m i == j i j j == m j m {
						ans += i;
					} ans += i ans i {
						ans += gcd(i, j, m);
					} ans += gcd(i, j, m) ans gcd(i, j, m) gcd i j m System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	} gcd {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	} final int len = param.length; len param.length param param.length int g = gcd(param[0], param[1]); g gcd(param[0], param[1]) gcd param[0] param 0 param[1] param 1 for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		} int i = 1; int i = 1; i 1 i < len - 1 i len - 1 len 1 i++ i++ i {
			g = gcd(g, param[i + 1]);
		} {
			g = gcd(g, param[i + 1]);
		} g = gcd(g, param[i + 1]) g gcd(g, param[i + 1]) gcd g param[i + 1] param i + 1 i 1 return g; g final int... param param public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	} gcd {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	} if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		} a < b a b {
			int tmp = a;
			a = b;
			b = tmp;
		} int tmp = a; tmp a a = b a b b = tmp b tmp int r = -1; r -1 1 while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		} r != 0 r 0 {
			r = a % b;
			a = b;
			b = r;
		} r = a % b r a % b a b a = b a b b = r b r return a; a int a a int b b public class Main {
	public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
} public class Main {
	public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
}