import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		ArrayList<Integer> c = sosu(200);
		for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		}
		System.out.println(b);
	}
	static int gcd(int a,int b,int c,ArrayList s) {
		int d = 1;
		for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		}
		return d;
	}
	static ArrayList sosu(int a) {
		int[] b = new int[a];
		for(int i = 0; i < a; i++) {
			b[i] = i+1;
		}
		for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		}
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		}
		return al;
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		ArrayList<Integer> c = sosu(200);
		for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		}
		System.out.println(b);
	}
	static int gcd(int a,int b,int c,ArrayList s) {
		int d = 1;
		for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		}
		return d;
	}
	static ArrayList sosu(int a) {
		int[] b = new int[a];
		for(int i = 0; i < a; i++) {
			b[i] = i+1;
		}
		for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		}
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		}
		return al;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		ArrayList<Integer> c = sosu(200);
		for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		}
		System.out.println(b);
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		ArrayList<Integer> c = sosu(200);
		for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		}
		System.out.println(b);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = 0; b 0 ArrayList<Integer> c = sosu(200); c sosu(200) sosu 200 for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		} int i = 1; int i = 1; i 1 i < a+1 i a+1 a 1 i++ i++ i {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		} {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		} for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			} int j = 1; int j = 1; j 1 j < a+1 j a+1 a 1 j++ j++ j {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			} {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			} for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				} int k = 1; int k = 1; k 1 k < a+1 k a+1 a 1 k++ k++ k {
					b += gcd(i,j,k,c);
				} {
					b += gcd(i,j,k,c);
				} b += gcd(i,j,k,c) b gcd(i,j,k,c) gcd i j k c System.out.println(b) System.out.println System.out System System.out b String[] args args static int gcd(int a,int b,int c,ArrayList s) {
		int d = 1;
		for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		}
		return d;
	} gcd {
		int d = 1;
		for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		}
		return d;
	} int d = 1; d 1 for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i < s.size() i s.size() s.size s i++ i++ i {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		} {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		} int ss = (int)s.get(i); ss (int)s.get(i) s.get s i if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			} ss != 0 ss 0 {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			} if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				} a%ss == 0 && b%ss == 0 && c%ss == 0 a%ss == 0 && b%ss == 0 && c%ss == 0 a%ss == 0 a%ss a ss 0 b%ss == 0 b%ss b ss 0 c%ss == 0 c%ss c ss 0 {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				} while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					} true {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					} d *= ss d ss a /= ss a ss b /= ss b ss c /= ss c ss if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break; !(a%ss == 0 && b%ss == 0 && c%ss == 0) (a%ss == 0 && b%ss == 0 && c%ss == 0) a%ss == 0 && b%ss == 0 && c%ss == 0 a%ss == 0 a%ss a ss 0 b%ss == 0 b%ss b ss 0 c%ss == 0 c%ss c ss 0 break; return d; d int a a int b b int c c ArrayList s s static ArrayList sosu(int a) {
		int[] b = new int[a];
		for(int i = 0; i < a; i++) {
			b[i] = i+1;
		}
		for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		}
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		}
		return al;
	} sosu {
		int[] b = new int[a];
		for(int i = 0; i < a; i++) {
			b[i] = i+1;
		}
		for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		}
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		}
		return al;
	} int[] b = new int[a]; b new int[a] a for(int i = 0; i < a; i++) {
			b[i] = i+1;
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			b[i] = i+1;
		} {
			b[i] = i+1;
		} b[i] = i+1 b[i] b i i+1 i 1 for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		} int i = 1; int i = 1; i 1 i < a i a i++ i++ i {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		} {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		} if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			} b[i] != 0 b[i] b i 0 {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			} for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				} int j = 0; int j = 0; j 0 j < a j a j++ j++ j {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				} {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				} if(i != j && b[j] % b[i] == 0)b[j] =0; i != j && b[j] % b[i] == 0 i != j i j b[j] % b[i] == 0 b[j] % b[i] b[j] b j b[i] b i 0 b[j] =0 b[j] b j 0 ArrayList<Integer> al = new ArrayList<Integer>(); al new ArrayList<Integer>() for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		} {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		} if(b[i] != 0) {
				al.add(b[i]);
			} b[i] != 0 b[i] b i 0 {
				al.add(b[i]);
			} al.add(b[i]) al.add al b[i] b i return al; al int a a
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		ArrayList<Integer> c = sosu(200);
		for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		}
		System.out.println(b);
	}
	static int gcd(int a,int b,int c,ArrayList s) {
		int d = 1;
		for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		}
		return d;
	}
	static ArrayList sosu(int a) {
		int[] b = new int[a];
		for(int i = 0; i < a; i++) {
			b[i] = i+1;
		}
		for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		}
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		}
		return al;
	}
}
