import java.util.Scanner;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

	}
} Main public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc long sum = 0; sum 0 for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		} {
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		} for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			} int k = 1; int k = 1; k 1 k <= N k N k++ k++ k {
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			} {
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			} for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				} int l = 1; int l = 1; l 1 l <= N l N l++ l++ l {

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				} {

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				} int x = i; x i int y = k; y k int z = l; z l int tmp; tmp while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					} x % y != 0 x % y x y 0 {
						tmp = (x % y);
						x = y;
						y = tmp;
					} tmp = (x % y) tmp (x % y) x y x = y x y y = tmp y tmp while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					} y % z != 0 y % z y z 0 {
						tmp = (y % z);
						y = z;
						z = tmp;
					} tmp = (y % z) tmp (y % z) y z y = z y z z = tmp z tmp sum += z sum z System.out.print(sum) System.out.print System.out System System.out sum return; String[] args args public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

	}
} public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long sum = 0;



		for(int i = 1; i <= N; i++){
			for (int k = 1; k <= N; k++){
				for (int l = 1; l <= N; l++){

					int x = i;
					int y = k;
					int z = l;
					int tmp;

					while (x % y != 0){
						tmp = (x % y);
						x = y;
						y = tmp;
					}

					while (y % z != 0){
						tmp = (y % z);
						y = z;
						z = tmp;
					}

					sum += z;

				}
			}
		}

		System.out.print(sum);

	return;

	}
}
