import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	}
	
	public static long gcd (long a, long b, long c) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	}
	
	public static long gcd (long a, long b, long c) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	}
} Main public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Long n = scan.nextLong(); n scan.nextLong() scan.nextLong scan long ans = 0; ans 0 for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		} int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		} {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		} for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			} int j = 1; int j = 1; j 1 j < n + 1 j n + 1 n 1 j++ j++ j {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			} {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			} for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				} int k = 1; int k = 1; k 1 k < n + 1 k n + 1 n 1 k++ k++ k {
					ans = ans + gcd(i, j, k);
				} {
					ans = ans + gcd(i, j, k);
				} ans = ans + gcd(i, j, k) ans ans + gcd(i, j, k) ans gcd(i, j, k) gcd i j k System.out.println(ans) System.out.println System.out System System.out ans String args[] args public static long gcd (long a, long b, long c) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	} gcd {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	} long temp; temp while((temp = a%b)!=0) {
			a = b;
			b = temp;
		} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
			a = b;
			b = temp;
		} a = b a b b = temp b temp while((temp = c%b)!=0) {
			c = b;
			b = temp;
		} (temp = c%b)!=0 (temp = c%b) temp c%b c b 0 {
			c = b;
			b = temp;
		} c = b c b b = temp b temp return b; b long a a long b b long c c public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	}
	
	public static long gcd (long a, long b, long c) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	}
} public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	}
	
	public static long gcd (long a, long b, long c) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		Long n = scan.nextLong();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				for(int k = 1; k < n + 1; k++) {
					ans = ans + gcd(i, j, k);
				}
			}
		}
		System.out.println(ans);
	}
	
	public static long gcd (long a, long b, long c) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		
		while((temp = c%b)!=0) {
			c = b;
			b = temp;
		}
		return b;
	}
}