import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	}

	public static int calcGcd(int i, int j, int k) {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	}

	public static int calcGcd(int i, int j, int k) {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	}

} Main public static void main(String[] args) {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	} main {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	} int ans = 0; ans 0 Scanner in = new Scanner(System.in); in new Scanner(System.in) String str = in.next(); str in.next() in.next in int K = Integer.parseInt(str); K Integer.parseInt(str) Integer.parseInt Integer str for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		} int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		} {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		} for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			} int j = i; int j = i; j i j <= K j K j++ j++ j {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			} {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			} for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				} int k = j; int k = j; k j k <= K k K k++ k++ k {
					ans += calcGcd(i, j, k);
				} {
					ans += calcGcd(i, j, k);
				} ans += calcGcd(i, j, k) ans calcGcd(i, j, k) calcGcd i j k System.out.println(ans) System.out.println System.out System System.out ans in.close() in.close in String[] args args public static int calcGcd(int i, int j, int k) {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	} calcGcd {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	} int p = k p k q = j q j temp temp num = 6; num 6 if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		} i == j && j == k i == j i j j == k j k {
			num = 1;
		} num = 1 num 1 if (i == j || j == k) {
			num = 3;
		} i == j || j == k i == j i j j == k j k {
			num = 3;
		} num = 3 num 3 while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		} p % q != 0 p % q p q 0 {
			temp = p % q;
			p = q;
			q = temp;
		} temp = p % q temp p % q p q p = q p q q = temp q temp if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		} i < q i q {
			p = q;
			q = i;
		} p = q p q q = i q i {
			p = i;
		} p = i p i while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		} p % q != 0 p % q p q 0 {
			temp = p % q;
			p = q;
			q = temp;
		} temp = p % q temp p % q p q p = q p q q = temp q temp return q * num; q * num q num int i i int j j int k k public class Main {
	public static void main(String[] args) {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	}

	public static int calcGcd(int i, int j, int k) {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	}

} public class Main {
	public static void main(String[] args) {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	}

	public static int calcGcd(int i, int j, int k) {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int ans = 0;
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int K = Integer.parseInt(str);

		for (int i = 1; i <= K; i++) {
			for (int j = i; j <= K; j++) {
				for (int k = j; k <= K; k++) {
					ans += calcGcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
		in.close();
	}

	public static int calcGcd(int i, int j, int k) {// i<j<k
		int p = k, q = j, temp, num = 6;
		if (i == j && j == k) {
			num = 1;
		} else if (i == j || j == k) {
			num = 3;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		if (i < q) {
			p = q;
			q = i;
		} else {
			p = i;
		}
		while (p % q != 0) {
			temp = p % q;
			p = q;
			q = temp;
		}
		return q * num;
	}

}