import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		} int a = 1; int a = 1; a 1 a <= K a K a++ a++ a {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		} {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		} for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			} int b = 1; int b = 1; b 1 b <= K b K b++ b++ b {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			} {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			} for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 } int c = 1; int c = 1; c 1 c <= K c K c++ c++ c {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 } {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 } int min = c; min c if (b < c) min = b; b < c b c min = b min b if (a < b) min = a; a < b a b min = a min a int com = 0; com 0 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 } int i = min; int i = min; i min 1 <= i 1 i i-- i-- i {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 } {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 } if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 } a%i == 0 && b%i == 0 && c%i == 0 a%i == 0 && b%i == 0 && c%i == 0 a%i == 0 a%i a i 0 b%i == 0 b%i b i 0 c%i == 0 c%i c i 0 {
							 com = i;
							 break;
						 } com = i com i break; count += com count com System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	}
} Main
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	}
}