import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		}
		
		private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		}
	}
	

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		private int nextInt() {
			return Integer.parseInt(next());
		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.OutputStream; OutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		}
		
		private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		}
	}
	

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		private int nextInt() {
			return Integer.parseInt(next());
		}
	}

} Main public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	} main {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	} InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) new Solution().solve(in, out) new Solution().solve new Solution() in out out.close() out.close out String[] args args private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		}
		
		private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		}
	} Solution private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		} solve {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		} int k = in.nextInt(); k in.nextInt() in.nextInt in long ans = 0; ans 0 for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c); 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)
						ans += gcd(gcd(a, b), c); for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c); int b = 1; int b = 1; b 1 b <= k b k ++b ++b b for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c); for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c); int c = 1; int c = 1; c 1 c <= k c k ++c ++c c ans += gcd(gcd(a, b), c); ans += gcd(gcd(a, b), c) ans gcd(gcd(a, b), c) gcd gcd(a, b) gcd a b c out.println(ans) out.println out ans InputReader in in PrintWriter out out private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		} gcd {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		} while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			} b != 0 b 0 {
				long m = a % b;
				a = b;
				b = m;
			} long m = a % b; m a % b a b a = b a b b = m b m return a; a long a a long b b private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		private int nextInt() {
			return Integer.parseInt(next());
		}
	} InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		} InputReader {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		} reader = new BufferedReader(new InputStreamReader(stream), 32678) reader new BufferedReader(new InputStreamReader(stream), 32678) tokenizer = null tokenizer null InputStream stream stream public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		} next {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		} while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			} tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			} try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} IOException e {
					throw new RuntimeException(e);
				} throw new RuntimeException(e); new RuntimeException(e) {
					tokenizer = new StringTokenizer(reader.readLine());
				} tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer private int nextInt() {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		}
		
		private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		}
	}
	

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		private int nextInt() {
			return Integer.parseInt(next());
		}
	}

} public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		}
		
		private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		}
	}
	

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		private int nextInt() {
			return Integer.parseInt(next());
		}
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new Solution().solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.nextInt();
			long ans = 0;
			for (int a = 1; a <= k; ++a)
				for (int b = 1; b <= k; ++b)
					for (int c = 1; c <= k; ++c)
						ans += gcd(gcd(a, b), c);
			out.println(ans);
		}
		
		private long gcd(long a, long b) {
			while (b != 0) {
				long m = a % b;
				a = b;
				b = m;
			}
			return a;
		}
	}
	

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32678);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		private int nextInt() {
			return Integer.parseInt(next());
		}
	}

}
