

import java.util.Scanner;

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

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	}

	private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	}

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

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	}

	private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	}

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

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

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

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		} int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		} {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		} for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			} int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			} {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			} for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				} int l = 1; int l = 1; l 1 l <= k l k l++ l++ l {
					ans += gcd(i, gcd(j, l));
				} {
					ans += gcd(i, gcd(j, l));
				} ans += gcd(i, gcd(j, l)) ans gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	} gcd {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	} int c = 0; c 0 int r = 1; r 1 if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		} a > b a b {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} 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 c = a c a if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		} b > a b a {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			} r > 0 r 0 {
				r = b % a;
				b = a;
				a = r;
			} r = b % a r b % a b a b = a b a a = r a r c = b c b {
			c = a;
		} c = a c a return c; c int a a int b b public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	}

	private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	}

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

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	}

	private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	}

} Main


import java.util.Scanner;

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

		int k = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					ans += gcd(i, gcd(j, l));
				}
			}
		}

		System.out.println(ans);

	}

	private static int gcd(int a, int b) {
		int c = 0;
		int r = 1;

		if (a > b) {

			while (r > 0) {
				r = a % b;
				a = b;
				b = r;
			}
			c = a;

		} else if (b > a) {
			while (r > 0) {
				r = b % a;
				b = a;
				a = r;
			}
			c = b;
		} else {
			c = a;
		}

		return c;
	}

}
