import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	}

	public static int gcd(int p, int q) {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	}

	public static int gcd(int p, int q) {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	} main {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		} int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		} {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		} for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			} int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			} {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			} for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				} int h = 1; int h = 1; h 1 h <= K h K h++ h++ h {

					sum += gcd(i, gcd(j, h));
				} {

					sum += gcd(i, gcd(j, h));
				} sum += gcd(i, gcd(j, h)) sum gcd(i, gcd(j, h)) gcd i gcd(j, h) gcd j h System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int p, int q) {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	} gcd {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	} if (p % q == 0) {
			return q;
		} p % q == 0 p % q p q 0 {
			return q;
		} return q; q return gcd(q, p % q); gcd(q, p % q) gcd q p % q p q int p p int q q public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	}

	public static int gcd(int p, int q) {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	}

	public static int gcd(int p, int q) {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int h = 1; h <= K; h++) {

					sum += gcd(i, gcd(j, h));
				}
			}
		}
		System.out.println(sum);

	}

	public static int gcd(int p, int q) {

		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	}
}