import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	}

	public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	}

	public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	} main {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A = sc.nextInt(); A sc.nextInt() sc.nextInt sc long ans = 0; ans 0 Main main = new Main(); main new Main() for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		} int i = 1; int i = 1; i 1 i <= A i A i++ i++ i {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		} {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		} for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			} int j = 1; int j = 1; j 1 j <= A j A j++ j++ j {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			} {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			} for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				} int k = 1; int k = 1; k 1 k <= A k A k++ k++ k {
					ans += main.GCD(i, main.GCD(j, k));
				} {
					ans += main.GCD(i, main.GCD(j, k));
				} ans += main.GCD(i, main.GCD(j, k)) ans main.GCD(i, main.GCD(j, k)) main.GCD main i main.GCD(j, k) main.GCD main j k System.out.println(ans) System.out.println System.out System System.out ans String[] args args public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	} GCD {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	} if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		} num2 == 0 num2 0 {
			return num1;
		} return num1; num1 {
			return GCD(num2, num1 % num2);
		} return GCD(num2, num1 % num2); GCD(num2, num1 % num2) GCD num2 num1 % num2 num1 num2 int num1 num1 int num2 num2 public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	}

	public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	}

	public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	}

	public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}

}