import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	}

} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int K = Integer.parseInt(br.readLine()); K Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br long sum = 0; sum 0 for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		} int i=1; int i=1; i 1 i<K+1 i K+1 K 1 i++ i++ i {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		} {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		} for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			} int j=1; int j=1; j 1 j<K+1 j K+1 K 1 j++ j++ j {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			} {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			} for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				} int k=1; int k=1; k 1 k<K+1 k K+1 K 1 k++ k++ k {
					sum += gcd(i, gcd(j, k));
				} {
					sum += gcd(i, gcd(j, k));
				} sum += gcd(i, gcd(j, k)) sum gcd(i, gcd(j, k)) gcd i gcd(j, k) gcd j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	} gcd {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	} while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		} b != 0 b 0 {
			int tmp = a % b;
			a = b;
			b = tmp;
		} int tmp = a % b; tmp a % b a b a = b a b b = tmp b tmp return Math.abs(a); Math.abs(a) Math.abs Math a int a a int b b public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	}

}