import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	}
	
	public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
	
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	}
	
	public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
	
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	} main {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) long K = in.nextLong(); K in.nextLong() in.nextLong in long sum = 0; sum 0 for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		} int i=1; int i=1; i 1 i<=K i K i++ i++ i {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		} {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		} for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			} int j=1; int j=1; j 1 j<=K j K j++ j++ j {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			} {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			} for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				} int k=1; int k=1; k 1 k<=K k K k++ k++ k {
					sum = sum + gcd(k, gcd(i,j));
				} {
					sum = sum + gcd(k, gcd(i,j));
				} sum = sum + gcd(k, gcd(i,j)) sum sum + gcd(k, gcd(i,j)) sum gcd(k, gcd(i,j)) gcd k gcd(i,j) gcd i j System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	} gcd {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	} if(y == 0) {
			return x;
		} y == 0 y 0 {
			return x;
		} return x; x return gcd(y, x%y); gcd(y, x%y) gcd y x%y x y int x x int y y public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	}
	
	public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
	
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	}
	
	public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
	
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long K = in.nextLong();
		long sum = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					sum = sum + gcd(k, gcd(i,j));
				}
			}
		}
		
		System.out.println(sum);
		
	}
	
	public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
	
}
