import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	}
} Main static Main instance = new Main(); instance new Main() public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	} main {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan long sum = 0L; sum 0L for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		} {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		} for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			} int j = 1; int j = 1; j 1 j <= N j N j++ j++ j {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			} {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			} for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				} int k = 1; int k = 1; k 1 k <= N k N k++ k++ k {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				} {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				} int x1 x1 y1; y1 if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					} i > j i j {
						x1 = i;
						y1 = j;
					} x1 = i x1 i y1 = j y1 j {
						x1 = j;
						y1 = i;
					} x1 = j x1 j y1 = i y1 i while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					} x1 % y1 != 0 x1 % y1 x1 y1 0 {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					} int tmp = x1; tmp x1 x1 = y1 x1 y1 y1 = (tmp % y1) y1 (tmp % y1) tmp y1 int x2 x2 y2; y2 if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					} y1 > k y1 k {
						x2 = y1;
						y2 = k;
					} x2 = y1 x2 y1 y2 = k y2 k {
						x2 = k;
						y2 = y1;
					} x2 = k x2 k y2 = y1 y2 y1 while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					} x2 % y2 != 0 x2 % y2 x2 y2 0 {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					} int tmp = x2; tmp x2 x2 = y2 x2 y2 y2 = tmp % y2 y2 tmp % y2 tmp y2 sum += y2 sum y2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	}
} public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	}
} Main
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	}
}