import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	}

	private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	}

	private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	} main {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int[][] dp = new int[201][201]; dp new int[201][201] 201 201 long res = 0; res 0 for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		} int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		} {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		} for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			} int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			} {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			} int gcd; gcd if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				} dp[i][j] == 0 dp[i][j] dp[i] dp i j 0 {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} gcd = gcd(i, j) gcd gcd(i, j) gcd i j dp[i][j] = gcd dp[i][j] dp[i] dp i j gcd {
					gcd = dp[i][j];
				} gcd = dp[i][j] gcd dp[i][j] dp[i] dp i j for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				} int k = 1; int k = 1; k 1 k <= K k K k++ k++ k {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				} {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				} int gcd3; gcd3 if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					} dp[gcd][k] == 0 dp[gcd][k] dp[gcd] dp gcd k 0 {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} gcd3 = gcd(gcd, k) gcd3 gcd(gcd, k) gcd gcd k dp[gcd][k] = gcd3 dp[gcd][k] dp[gcd] dp gcd k gcd3 {
						gcd3 = dp[gcd][k];
					} gcd3 = dp[gcd][k] gcd3 dp[gcd][k] dp[gcd] dp gcd k res += gcd3 res gcd3 System.out.println(res) System.out.println System.out System System.out res String[] args args private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	} gcd {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	} while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		} i != 0 && j != 0 i != 0 i 0 j != 0 j 0 {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		} if (i < j) {
				j %= i;
			} else {
				i %= j;
			} i < j i j {
				j %= i;
			} j %= i j i {
				i %= j;
			} i %= j i j return Math.max(i, j); Math.max(i, j) Math.max Math i j int i i int j j public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	}

	private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	}

	private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	}

	private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	}
}