import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	}

	private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	}
} 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();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	}

	private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

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


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	} main {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc long answer = 0; answer 0 for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		} int a = 1; int a = 1; a 1 a <=k a k a++ a++ a {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		} {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		} for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			} int b = 1; int b = 1; b 1 b <=k b k b++ b++ b {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			} {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			} int tmp = getMaxKoyakusu(a,b); tmp getMaxKoyakusu(a,b) getMaxKoyakusu a b for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				} int c = 1; int c = 1; c 1 c <=k c k c++ c++ c {
					answer+= getMaxKoyakusu(tmp,c);
				} {
					answer+= getMaxKoyakusu(tmp,c);
				} answer+= getMaxKoyakusu(tmp,c) answer getMaxKoyakusu(tmp,c) getMaxKoyakusu tmp c System.out.println(answer) System.out.println System.out System System.out answer String[] args args private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	} getMaxKoyakusu {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	} int base = a; base a if(base > b) {
			base =b;
		} base > b base b {
			base =b;
		} base =b base b for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		} int i =base; int i =base; i base i >=1 i 1 i-- i-- i {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		} {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		} if(a % i !=0) {
				continue;
			} a % i !=0 a % i a i 0 {
				continue;
			} continue; if(b % i !=0) {
				continue;
			} b % i !=0 b % i b i 0 {
				continue;
			} continue; return i; i return 1; 1 int a a int b b public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	}

	private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	}
} public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	}

	private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	}

	private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	}
}