import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s = sc.nextLine(); s sc.nextLine() sc.nextLine sc long sum = 0; sum 0 int K = Integer.valueOf(s); K Integer.valueOf(s) Integer.valueOf Integer s for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		} int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		} {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		} for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			} int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			} {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			} for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				} int k = 1; int k = 1; k 1 k <= K k K k++ k++ k {
					sum += gcd(gcd(i, j), k);
				} {
					sum += gcd(gcd(i, j), k);
				} sum += gcd(gcd(i, j), k) sum gcd(gcd(i, j), k) gcd gcd(i, j) gcd i j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	} gcd {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	} if (a == 0)
			return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a int a a int b b public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

}
