import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	}
	
	public static int gcd(int a, int b) {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	}
	
	public static int gcd(int a, int b) {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	}

} Main public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	} main {
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	} try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		} {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int k= sc.nextInt(); k sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			} 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++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			} {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			} for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				} int b = 1 ; int b = 1 ; b 1 b <= k b k b++ b++ b {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				} {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				} for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					} int c = 1 ; int c = 1 ; c 1 c <= k c k c++ c++ c {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					} {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					} int gcd1 = gcd(a, b); gcd1 gcd(a, b) gcd a b int gcd2 = gcd(gcd1, c); gcd2 gcd(gcd1, c) gcd gcd1 c sum+= gcd2 sum gcd2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int a, int b) {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	} gcd {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	} if ( a < b ) {
			return gcd(b, a);
		} a < b a b {
			return gcd(b, a);
		} return gcd(b, a); gcd(b, a) gcd b a if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		} a % b == 0 a % b a b 0 {
			return b;
		} return b; b {
			return gcd(a % b, b);
		} return gcd(a % b, b); gcd(a % b, b) gcd a % b a b b int a a int b b public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	}
	
	public static int gcd(int a, int b) {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	}

} public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	}
	
	public static int gcd(int a, int b) {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			

			int k= sc.nextInt();
			
			int sum = 0;
			
			for(int a = 1 ; a <= k ; a++) {
				for(int b = 1 ; b <= k ; b++ ) {
					for(int c = 1 ; c <= k ; c++ ) {
						
						int gcd1 = gcd(a, b);
						int gcd2 = gcd(gcd1, c);
						
						sum+= gcd2;
					}
				}
			}
			
			System.out.println(sum);
		}
	}
	
	public static int gcd(int a, int b) {

		if ( a < b ) {
			return gcd(b, a);
		}
		
		if ( a % b == 0 ) {
			return b;
		}
		else {
			return gcd(a % b, b);
		}
	}

}