import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	}
 
} import java.util.Scanner; Scanner java.util public class Main {
 
	public static void main(String[] args) {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	}
 
} Main public static void main(String[] args) {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	} main {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		} 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++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		} {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		} for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			} int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
				for (int k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			} {
				for (int k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			} for (int k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				} int k = 1; int k = 1; k 1 k <= K k K k++ k++ k {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				} {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				} int tmp; tmp int i1 = i; i1 i int j1 = j; j1 j int k1 = k; k1 k while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					} (tmp = k1 % j1) != 0 (tmp = k1 % j1) tmp k1 % j1 k1 j1 0 {
						k1 = j1;
						j1 = tmp;
					} k1 = j1 k1 j1 j1 = tmp j1 tmp while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					} (tmp = j1 % i1) != 0 (tmp = j1 % i1) tmp j1 % i1 j1 i1 0 {
						j1 = i1;
						i1 = tmp;
					} j1 = i1 j1 i1 i1 = tmp i1 tmp sum += i1 sum i1 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
 
	public static void main(String[] args) {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	}
 
} public class Main {
 
	public static void main(String[] args) {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	}
 
} Main
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		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 k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	}
 
}